[python-win32] PumpMessages in main thread called by embedded Python causes crash

Mark Hammond skippy.hammond at gmail.com
Sun Apr 29 07:15:50 CEST 2012

I don't know why it crashes exactly, but if the other app has its own 
event loop then things are going to get screwey - PumpMessages never 
returns (well, not until a WM_QUIT message is received), so their event 
loop will never run.

I'd guess that their event loop and event handlers have some assumptions 
built in to it - eg, they might be assuming that their event loop as set 
something up that one of the message handlers relies on.  You running 
your own event loop will prevent that setup from happening so one of 
their handlers will crash.

Does that app work OK if you don't call PumpMessages?  If so, a work 
around might be to check if you have a console, and if you don't, assume 
some other event loop must be running.


On 29/04/2012 2:21 AM, reckoner wrote:
> I have written some code that catches windows events that also includes
> the usual PumpMessages, and all of this works fine when I run it from
> the Python interpreter (Python version 2.6). However, when a separate
> application that has Python embedded calls the same code,  the calling
> application crashes. I have tracked this down to the PumpMessages call
> in my code.
> My question is why does this work perfectly well from the interpreter,
> but cause a crash when called from the embedded Python running in a
> separate application. Note that I don't have access to the separate
> application in which the Python call is embedded and when it crashes it
> does not provide any kind of traceback.  It took a long time to narrow
> it down to the PumpMessages call.
> Any advice appreciated. I am really stuck here. By the way, this is on
> Windows XP 32-bit.
> Thanks!
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32

More information about the python-win32 mailing list