[Tutor] How can I catch a Windows event?

goldperger at st.nograd.net goldperger at st.nograd.net
Sun Aug 29 11:03:54 CEST 2004

I am new in computing and python. My problem is during
switching off/ restaring Win 98 the phyton script written by me
doesn’t stop. (in Win XP. no problem)

I gues it is because of a thread. By checking from the internet
I found the WM_QUERYENDSESSION should be caught for regular
stopping, but I do not understand how.

I am also not sure, which I should use win 32all or wxPython.
The following script stops the win98 shutdown process if I start the script from consol.

python 2.3.3 Win98SE

from threading import Thread
from time import sleep

stop_now=0  #It must changed into 1 when event WM_QUERYENDSESSION happens

class Test_thread_app(Thread):
    def run(self):
	global stop_now
        while n<10 and (not stop_now):
            print str(n) 

if __name__=="__main__":


Is there any solution for catching this kind of event?
Is there other solution advised?

Andras Goldperger

More information about the Tutor mailing list