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 [hidden email] http://mail.python.org/mailman/listinfo/python-win32 |
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. Mark 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 > [hidden email] > http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list [hidden email] http://mail.python.org/mailman/listinfo/python-win32 |
Thanks for your reply.
Yes, the app works fine if I don't PumpMessages in my own code. There is no console that the application fires up when it runs the embedded Python code. In this situation, how do I (or, can I?) pump for my own messages if the application is doing some other kind of event loop, as you describe? Thanks! On Saturday, April 28, 2012 10:15:50 PM, Mark Hammond wrote: > 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. > > Mark > > 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 >> [hidden email] >> http://mail.python.org/mailman/listinfo/python-win32 > > python-win32 mailing list [hidden email] http://mail.python.org/mailman/listinfo/python-win32 |
On 30/04/2012 1:07 AM, reckoner wrote:
> Thanks for your reply. > > Yes, the app works fine if I don't PumpMessages in my own code. There is > no console that the application fires up when it runs the embedded > Python code. In this situation, how do I (or, can I?) pump for my own > messages if the application is doing some other kind of event loop, as > you describe? The event loop isn't generally where you handle messages - messages are generally handled in a WndProc or similar (ie, by using something like win32gui and its message handling support). You might also want to look into hooking messages (pythonwin has some support for that, and another package called PyHook might also help). Mark > > Thanks! > > > > On Saturday, April 28, 2012 10:15:50 PM, Mark Hammond wrote: >> 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. >> >> Mark >> >> 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 >>> [hidden email] >>> http://mail.python.org/mailman/listinfo/python-win32 >> >> _______________________________________________ python-win32 mailing list [hidden email] http://mail.python.org/mailman/listinfo/python-win32 |
On 4/29/2012 3:48 PM, Mark Hammond wrote: > On 30/04/2012 1:07 AM, reckoner wrote: >> Thanks for your reply. >> >> Yes, the app works fine if I don't PumpMessages in my own code. There is >> no console that the application fires up when it runs the embedded >> Python code. In this situation, how do I (or, can I?) pump for my own >> messages if the application is doing some other kind of event loop, as >> you describe? > > The event loop isn't generally where you handle messages - messages are > generally handled in a WndProc or similar (ie, by using something like > win32gui and its message handling support). You might also want to look > into hooking messages (pythonwin has some support for that, and another > package called PyHook might also help). > > Mark >> Yes, I use PyHook on another project, but here I need to hook more than mouse and keyboard messages. I need window-open/close, etc. According to this thread: http://stackoverflow.com/questions/6458812/python-ctypes-setwindowshookex-callback-function-never-called this is not possible directly and I have been successful using the pyAA (Microsoft Active Accessibility) bindings to catch these other messages, and this works beautifully otherwise, except for this case where the embedded application (not a GUI, BTW) will not let me pump messages to flush out the events that pyAA can catch. Any other ideas? The only other idea I have is to create a separate Python process that will listen for specific messages using pyAA and then return output on a socket that the application's embedded Python can later query. Thanks again. (I read your great book by the way!) _______________________________________________ python-win32 mailing list [hidden email] http://mail.python.org/mailman/listinfo/python-win32 |
I'm afraid my only other idea is to contact the vendor of the other app
and see if they can shed any light on the problem... Cheers, Mark On 30/04/2012 10:49 AM, reckoner wrote: > > > On 4/29/2012 3:48 PM, Mark Hammond wrote: >> On 30/04/2012 1:07 AM, reckoner wrote: >>> Thanks for your reply. >>> >>> Yes, the app works fine if I don't PumpMessages in my own code. There is >>> no console that the application fires up when it runs the embedded >>> Python code. In this situation, how do I (or, can I?) pump for my own >>> messages if the application is doing some other kind of event loop, as >>> you describe? >> >> The event loop isn't generally where you handle messages - messages are >> generally handled in a WndProc or similar (ie, by using something like >> win32gui and its message handling support). You might also want to look >> into hooking messages (pythonwin has some support for that, and another >> package called PyHook might also help). >> >> Mark >>> > > Yes, I use PyHook on another project, but here I need to hook more than > mouse and keyboard messages. I need window-open/close, etc. According to > this thread: > > http://stackoverflow.com/questions/6458812/python-ctypes-setwindowshookex-callback-function-never-called > > > this is not possible directly and I have been successful using the pyAA > (Microsoft Active Accessibility) bindings to catch these other messages, > and this works beautifully otherwise, except for this case where the > embedded application (not a GUI, BTW) will not let me pump messages to > flush out the events that pyAA can catch. > > Any other ideas? The only other idea I have is to create a separate > Python process that will listen for specific messages using pyAA and > then return output on a socket that the application's embedded Python > can later query. > > Thanks again. (I read your great book by the way!) > > > > > _______________________________________________ python-win32 mailing list [hidden email] http://mail.python.org/mailman/listinfo/python-win32 |
Free forum by Nabble | Edit this page |