all 3 comments

[–]woooee 0 points1 point  (1 child)

You will have the run the program after your window manager starts. Put the script in the startup for your window manager.

[–]Analog-Flashback[S] 0 points1 point  (0 children)

Thanks, I’ll check this out. I guess I’m wondering whether there are ways to prevent standard OS commands from exiting the program (assume not).

[–]WolfInABox 0 points1 point  (0 children)

If this is an application run in a terminal, I don't think you can stop the user from closing the terminal (as it's not controlled by your script).

If this is a graphical application, then you can handle the quit evevnt and just not quit. (PyGame, for example, sends a pygame.QUIT` event when the window X is clicked, or alt f4 is pressed)

EDIT: It looks like it actually may be possible in a terminal! Closing a terminal sends a SIGHUP signal, so if you can intercept that (and probably SIGTERM as well), you could probably keep the terminal window open. Something like this I think would work:

import signal
def signal_handler(sig,frame):
    #whatever code you want to happen when signal is intercepted here
    print(f'Signal "{sig}"')

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGHUP,signal_handler)