EVT_QUERY_END_SESSION not firing?

The EVT_QUERY_END_SESSION event doesn't seem to be working for me. I'm
using python 2.4.3 on windows xp sp2 / windows xp 64-bit with wxPython
version '2.8.4.2 (msw-ansi)'. My script is below. I'm testing this
script by logging into another machine, opening a command prompt and
running this command line:

python h:\QueryEndSession.py > h:\stdout.txt 2> h:\stderr.txt

Then I log out. My Python scripts exits right after clicking the log off
button despite all the time.sleep calls, which tells me none of my event
handlers are being called. Also checking the content of stdout.txt after
the logout is complete also yields unexpected results, as none of the
print statements in my event handlers are executing.

I'm not sure what I'm doing wrong.

Here is the script:

import wx;
import sys;
import time;

class MyApp(wx.App):
    def __init__(self):
        wx.App.__init__(self, redirect=False);
        
    def OnInit(self):
        self.Bind( wx.EVT_QUERY_END_SESSION , self._onQueryEndSession )
        self.Bind( wx.EVT_END_SESSION , self._onEndSession )
        self.frame = wx.Frame(parent=None);
        self.frame.Show();
        self.frame.Bind(wx.EVT_CLOSE, self._onFrameClose);
        self.SetTopWindow(self.frame);
        return True;
    
    def OnExit(self):
        print "OnExit"
        sys.stdout.flush();
        time.sleep(5);
    
    def OnQueryEndSession(self):
        print "OnQueryEndSession"
        sys.stdout.flush();
        time.sleep(5);
        
    def _onQueryEndSession(self,event):
        print "_onQueryEndSession"
        sys.stdout.flush();
        time.sleep(5);
                
    def _onEndSession(self,event):
        print "_onEndSession"
        sys.stdout.flush();
        time.sleep(5);

    def _onFrameClose(self, event):
        print ("_onFrameClose, event: " + str(event));
        sys.stdout.flush();
        time.sleep(5);
        self.frame.Destroy();

def main():
    print "start"
    sys.stdout.flush();
    app = MyApp();
    app.MainLoop()
    print "end"
    sys.stdout.flush();

if __name__ == '__main__':
    main()

James Vecore wrote:

The EVT_QUERY_END_SESSION event doesn't seem to be working for me. I'm
using python 2.4.3 on windows xp sp2 / windows xp 64-bit with wxPython
version '2.8.4.2 (msw-ansi)'. My script is below. I'm testing this
script by logging into another machine, opening a command prompt and
running this command line:

python h:\QueryEndSession.py > h:\stdout.txt 2> h:\stderr.txt

Then I log out. My Python scripts exits right after clicking the log off
button despite all the time.sleep calls, which tells me none of my event
handlers are being called. Also checking the content of stdout.txt after
the logout is complete also yields unexpected results, as none of the
print statements in my event handlers are executing.

I'm not sure what I'm doing wrong.

This is a known bug that I haven't yet been able to track down the cause of. Something somewhere is derailing the end session events.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!