Using threads to quit the main python process

sharpblade sharpblade1 at
Wed Oct 29 01:42:16 CET 2008

Is there a way I can use threads to quit the main python process?
In brief, I have a python script that starts when my computer starts. It
chooses a random wallpaper background out of a specified path, and sets it
as the desktop wallpaper. It also hooks some windows hot keys so I can cycle
through all the wallpapers, or choose another one, or quit it, by using F8,
F7 and F6 respectively.
However, I would quite like the script to self-terminate if no user input is
received after X seconds. At first this seemed simple - Create a separate
thread that used time.sleep() to sleep for X seconds, then run a callback.
The callback would check a simple Boolean (Set to True if a hot key is
pressed, set to False at start of the script), and if the Boolean was False,
it would simply run exit(), and this would close the window.

However, it is not that simple. The callback and the thread work fine, but
the exit() seems to close the THREAD, not the main process. I have tried
sys.exit(), and some other forms I found on the Internet (Raising exceptions
and setting the thread to a daemon), but none seemed to close the actual
interpreter. I tried using the .join() function, but this called an
exception that told me the thread could not be joined.

Here is my code:

Thanks for reading,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list