Bugs item #3008512, was opened at 2010-05-28 22:30
Message generated for change (Comment added) made by mhammond
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3008512&group_id=78018
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: com
Group: None
>Status: Pending
Resolution: None
Priority: 5
Private: No
Submitted By: Klaus Noekel (kahlbutz)
Assigned to: Nobody/Anonymous (nobody)
Summary: COM server built with pythoncom crashes on second call
Initial Comment:
I am experiencing crashes with Python-based COM servers, if their methods use wxPython. I post the problem to this buglist, because I am not sure whether the effect is caused by wxPython or pywin32. Here is what happens:
My COM server is a slight variation of the small example from ch. 12 of Mark's book:
import wx
class PythonUtilities:
_public_methods_ = [ 'SplitString' ]
_reg_progid_ = "PythonAddIn.Runner"
# NEVER copy the following ID
# Use "print pythoncom.CreateGuid()" to make a new one.
_reg_clsid_ = "{91D9FEF4-B762-43AF-A0A5-965DA7B6A8EB}"
def SplitString(self, val, item=None):
import string
app = wx.PySimpleApp(0)
if item != None: item = str(item)
res = string.split(str(val), item)
for i,x in enumerate(res):
wx.MessageBox(str(x),str(i))
return res
# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__ == '__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
No, it does not do anything useful, but I managed to scale back the original example to this toy. Note that the method displays a few strings in a wx.MessageBox. Any call to wx causes the behavior described below.
Here is a VBA client for the server:
Sub COMTest()
Set Runner = CreateObject("PythonAddIn.Runner")
x = Runner.SplitString("fgh;jh;oei", ";")
Set Runner = Nothing
End Sub
Can't be much simpler than that. The first run of this client from Excel always succeeds, and three MessageBoxes pop up, as you would expect. The behavior on the second run (from the same Excel session) depends on the OS version running. Under Win 7 64-bit the second (and all subsequent) runs work just fine. Under XP SP2 32-bit the second run always crashes Excel. On OS's in between these two the second run may or may not crash, sometimes it even depends on the machine.
Versions used: Python 2.5.4, pywin32 -212, wxPython 2.8.9.1. The Excel version is unimportant, the crashes occur even in clients written in C++.
Any clue? I'd appreciate any advice!
Thanks,
Klaus Noekel
----------------------------------------------------------------------
>Comment By: Mark Hammond (mhammond)
Date: 2010-05-29 10:00
Message:
Starting a wxapp and showing UI as part of a COM object is always going to
be tricky. It is even possible to crash a non COM object simply by trying
to use wx with other GUI toolkits (eg, I expect you might have the same
problem trying to do the same thing from inside pythonwin?) Either way,
you are probably going to need to take this to the wx list...
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3008512&group_id=78018
|