Python COM server running as a singleton
marc.engel at recif.com
Thu Jan 17 18:20:15 CET 2002
I want to be able to get a COM server written in Python running as a
singleton. I also want to Dispatch it from VB and from Python and to
get the same instance.
Actually, it is the Python.Dictionary that I want to modify to get a
unique Dictionary in my system.
I have looked in this newsgroup to find a way to do it but I didn't
succeed in getting something working properly. I could only share the
same dictionary between Python Command line and Pythonwin but not with
VisualBasic. I should say that if VisualBasic create the singleton,
than Python can use it (Python first try to connect to the existing
object) but in the other direction, it didn't work.
Here is a solution I found using GetActiveObject. Maybe it can help
someone else, maybe this solution already exists. In any case,
comments are welcome.
I replaced the code from _CreateInstance_ method of DictionaryPolicy
def _CreateInstance_(self, clsid, reqIID):
# Do this to get it a singleton
# Try to get the existing instance of the object
object = win32com.client.GetActiveObject(DictionaryPolicy._reg_progid_)
# If the object is not in the list of Active object,
# we need to create it
object = pythoncom.WrapObject(self, reqIID)
More information about the Python-list