[python-win32] COM server with events and multiple threads

David Janssens dja at info.ucl.ac.be
Wed May 18 01:05:49 CEST 2005


Hello,

I am trying to build an application where the GUI is implemented as a 
VB6 exe and most of the core functionality is implemented as a python 
COM server that is called by the GUI.

The python COM server has multiple threads running in it and sends 
events once in a while to the VB6 GUI.

The python COM server needs to be run in the MTA of the application's 
process because all the events from the server to the GUI need to be 
marshalled, so I set the threading model of the python COM server to "free".

I distribute the whole application using py2exe.

However, I get the following error on some machines: "Class does not 
support Automation or does not support expected interface" when the 
python com server is loaded.

When I set the threading model to "both" instead of "free", the error 
disappears. But of course that doesn't suit me because then some VB6 gui 
code that handles COM server events gets called in threads that are 
different from the main gui thread.

I would like to know if someone has encountered this problem before or 
if there exists some samples that illustrate how to use a VB6 gui in 
conjunction with a python COM server that generates events and has 
multiple threads.

Thanks,
David Janssens

Here is the test code I use for the python COM server:

import sys
import pythoncom
import win32com.server
import win32com.server.connect
from win32com.server.exception import COMException
import winerror

IID_IServerWithEvents_Event = pythoncom.MakeIID('{11AEB37F-0CAB-4DE2-B975-F05567EADC8E}')
IID_IServerWithEvents = pythoncom.MakeIID('{938F1121-21ED-47A0-B0B7-47D7D6E99A7B}')

class Node(win32com.server.connect.ConnectableServer):
	_reg_desc_ = 'MyProject Node Component'
	_reg_clsid_ = '{49604ea4-bb2a-d04a-7fdd-b20e7e79cb40}'
	_reg_progid_ = 'MyProject.Node'
	_reg_threading_ = 'free' # Generates error, no errors with 'both'!
	_public_methods_ = ['run'] + win32com.server.connect.ConnectableServer._public_methods_
	_connect_interfaces_ = [IID_IServerWithEvents_Event]

	# Need to overload this method to tell that we support IID_IServerWithEvents
	def _query_interface_(self, iid):
		if iid == IID_IServerWithEvents:
			return win32com.server.util.wrap(self)

	def run(self):
		pass

if __name__=='__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(Node, debug=1)





More information about the Python-win32 mailing list