marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy

Home Page:https://vedo.embl.es

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exit viewer on control + c in terminal

emil-peters opened this issue · comments

When visualizing anything and exiting the python program using control + c it doesn't close the screen and also doesn't kill the python code

It only closes after focusing & clicking in the window again with the following prompt in the terminal afterwards:
Caught a Ctrl-C within python, exiting program.

Is there a way to automatically stop the visualizer after exiting the python program via the terminal?
On a custom VTK viewer we implemented using PyQT the following line seems to do the trick.

# This assures the app quits on CTRL-C (when not in focus)
signal.signal(signal.SIGINT, signal.SIG_DFL)

Visualization code example

        show(
            vedo_meshes,
            camera=camera,
            N=len(vedo_meshes),
            bg="black",
        ).close()

Thanks

I just tested and putting the following snippet at the top of the plotter.py file ensures that the code terminates on control-c in the terminal.
Not sure if this would be a desired solution or if there are other options

import signal

# This assures the app quits on CTRL-C (when not in focus)
signal.signal(signal.SIGINT, signal.SIG_DFL)

Hi, if you do CTRL-C focusing on the terminal that should terminate the app (maybe after some delay).
CTRL-C focusing on the rendering window will do nothing (although it would be good to have the same).

The way to close the window while focusing on it is to press q.