threaded COM server problem

Alexander Eisenhuth stacom at
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\", line 123, in on
     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

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 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()
	def excelCleanup (self):
		''' excel was ended
		global gCfgGuiThread
		print 'CEMISRGServer.excelCleanup:', gCfgGuiThread
		if gCfgGuiThread != None:

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

[the thread]
class CCfgGuiThread(threading.Thread):
	def run(self):
		import ergMain
		global gCfgGuiThread
		print ' >', gCfgGuiThread
		try : = 
		except Exception, msg:
			print '>>>> Exception caught in Dlg Thread <<<<<'
			print msg
			print '>>>> ------------------------------ <<<<<'
		print ' <'
		gCfgGuiThread = None	

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

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

[finally the GUI in modul]
def run (configurationFile=None, excelComClient=None):
	gUIApp = myApp()


More information about the Python-list mailing list