Menu

#675 win32ui crashes on exit with large wx Application

v1.0 (example)
open
nobody
win32ui (1)
5
2014-08-07
2014-08-07
ANoDE
No

Under Windows 8.1 / Python27 64Bit / pywin32 build 219 there seems to be a race condition during the shutdown of the application.

Debugging showed, that some Windows messages are sent AFTER the Python interpreter has already shut down (Py_Finalize already called).

The call to

//win32win.cpp:77 (inside Python_check_message)
CEnterLeavePython _celp;

is therefore working with a dead python instance and crashes.

Suggested fix:
The error can be prevented, if the following code is added to the win32uimodule.cpp file:

static void UnhookWindowsMessages() 
{
    if (hhook)
        UnhookWindowsHookEx(hhook);
    hhook = 0;
}

static void win32ui_finalize (void)
{
  UnhookWindowsMessages();
}

// At the end of PYWIN_MODULE_INIT_FUNC(win32ui):

  Py_AtExit(win32ui_finalize);

Working with Py_AtExit is not always the best choice, but in this case it seems legit.

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.