I have several daemon threads in my Python application. When my main function exits, these daemon threads terminate (as expected) and the program closes. But I want a way to essentially “restart” my program without exiting and starting it again. Is there a way to “force close” all of my daemon threads without calling sys.exit()?
I have several daemon threads in my Python application. When my main function exits,
Share
Mostly depends on your needs. If you want to save same type and reload
the application automatically this is not very difficult, take the
following example:
the script restarts itself while a certain condition is satisfied, then
exists. You could restart the application based on an event or a
signal, for example after a
SIGHUP.If you need also to save the current state the things are more
complicated. You can save the state of the application in a file before
restarting it and reload the state during the startup routine or you
have to instruct the daemon threads to exit on certain condition:
I hope these two example are useful to you to better understand your needs.