threaded COM server problem

Alexander Eisenhuth stacom at stacom-software.de
Thu Mar 6 17:34:53 CET 2003


Hello alltogether,

i wrote a application (a python com server), that creates a GUI (wxPython) on 
demand. In that case, it creates a thread and import the GUI stuff in the 
thread. I watch, that the GUI can only appear once.

Everything (GUI creation and destuction) works fine for a couple of times. 
(Ranges from ~5 to ~20 times). But sometime the wxPython stuff stucks after 
creation of the Window.

At anytime this exception is raised:
===================================
[...]
destroy - you really want ?
Traceback (most recent call last):
   File "F:\develop\frako\emis-report\EMIS-RG\src\ergDlgMain.py", line 123, in on
Cancel
     print 'destroy - you really want ?'
wxPython.wxc.wxPyAssertionError: C++ assertion "wxThread::IsMain()" failed in e:
\projects\wx\src\msw\app.cpp(870): only the main thread can process Windows mess
ages

OR Dr. Watson appears ...

So it sound to me, that wxPython gets confused with the threads (I've the most 2 
threads, thats what threading.activeCount() tells me)

I'm very thankfull for any hint ... (is there a better way to do it ?)

(python 2.2.2 win32all-152   wxPython 2.4.0.2) on Win2000

Here are fragments of my application:

[The COM server]
================
class CEMISRGServer:
	# com info settings
	_reg_clsid_      = '{76A42ED6-300B-4B6D-8013-A358E7BD35AA}'
	_reg_desc_       = 'EMIS-RG Server'
	_reg_progid_     = 'PythonServers.EMISRGServer'
	_public_methods_ = ['openConfigDialog', 'excelCleanup']
	_reg_clsctx_	= CLSCTX_LOCAL_SERVER

	# python methods
	def __init__(self):
		print 'CEMISRGServer.__init__'
		
	def openConfigDialog (self):
		global gCfgGuiThread
		print 'CEMISRGServer.openConfigDialog'
		if gCfgGuiThread == None:
			gCfgGuiThread = CCfgGuiThread()
			gCfgGuiThread.start()
			
	def excelCleanup (self):
		''' excel was ended
		'''
		global gCfgGuiThread
		print 'CEMISRGServer.excelCleanup:', gCfgGuiThread
		if gCfgGuiThread != None:
			gCfgGuiThread.exitThread()
			

	def __del__ (self):
		print 'CEMISRGServer.__del__'

[the thread]
============
class CCfgGuiThread(threading.Thread):
	def run(self):
		import ergMain
		global gCfgGuiThread
		print 'CCfgGuiThread.run >', gCfgGuiThread
		try :
			ergMain.run(configurationFile = 
'F:/develop/frako/emis-report/EMIS-RG/src/Test.erg')
		except Exception, msg:
			print '>>>> Exception caught in Dlg Thread <<<<<'
			print msg
			print '>>>> ------------------------------ <<<<<'
		print 'CCfgGuiThread.run <'
		gCfgGuiThread = None	

	def exitThread (self):
		import ergMain
		print 'CCfgGuiThread.exitThread'
		ergMain.UIExit()

	def __del__(self):
		global gCfgGuiThread
		print 'CCfgGuiThread.__del__'


[finally the GUI in modul ergMain.py]
=================
def run (configurationFile=None, excelComClient=None):
	
	pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
	gUIApp = myApp()
	gUIApp.MainLoop()
	pythoncom.CoUninitialize()


Regards
Alexander





More information about the Python-list mailing list