This is a bit similar to @Ian_Kennedy 's thread in April about threads being terminated on quit.
I have the case where the user wants to quit the app, which they can do by choosing the Quit menu item, clicking a Quit button, or closing the app’s main window, and some work they’ve done may need to be saved, which should happen at quit time. That work is done on a thread which needs to complete its work before the app quits.
So, in the app’s CancelClose event, I see whether a save is needed, and if so, trigger the thread to do the work and return True to cancel the Quit. I haven’t yet decided whether the saving thread or another which is monitoring it will then quit the app once the save is complete, but either way a thread needs to call Quit.
I tried with the montitoring thread calling Quit, but what happens in that the app becomes unresponsive but does not quit. I have to force-quit it.
So, can a thread safely call Quit?
Wondering whether the quit has to be done on the main thread, I added an event definition to the thread class, and raise that from within the thread. The handler for that just calls quit. This has made no difference - the app becomes unresponsive. I checked this through with the debugger and the code is executing as I intend - just not working.