[python-win32] Reusing a local com server object
Ross McKerchar
it at crummock.com
Wed Mar 7 11:05:04 CET 2007
Roger Upole wrote:
> Ross McKerchar wrote:
>
>> Any suggestions would be much appreciated - even just some key phrases
>> that may help energise my search efforts...
>>
> An object needs to be registered in the Running Object Table (ROT) for this to
> work. See pythoncom.RegisterActiveObject.
>
Ta very much - that's exactly the missing snippet I was looking for.
For posterity, here's my updated test solution:
-----------------------------------------------
class TestThread(threading.Thread):
def run(self):
pythoncom.CoInitialize()
wrapped = win32com.server.util.wrap(self.comobj)
handle = pythoncom.RegisterActiveObject(wrapped,
self.comobj._reg_clsid_, 0)
time.sleep(20)
pythoncom.RevokeActiveObject(handle)
class FaxJob(object):
_public_methods_ = ["go"]
_reg_progid_ = "pythonutils.test"
_reg_clsid_ = "{57E47876-69CB-4822-92F1-B8D2716F54A4}"
_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
testthread = TestThread()
def go(self):
if self.testthread.isAlive():
return "Server is already running"
else:
self.testthread.comobj = self
self.testthread.start()
return "Starting new server"
-----------------------------------------------
Many thanks.
-ross
More information about the Python-win32
mailing list