keeping a COM server alive

Stefan Schukat SSchukat at dspace.de
Thu Feb 17 04:22:31 EST 2005


Hi, 

there is no real solution if you are using a standard local server.
The server is as a COM object reference counted. So if the
reference count reaches 0 (no client) it will shutdown itself which
is done by design. If you want a different behavior you should write
either a service which exports COM objects and is started by the
operating system or a Python script which you start by hand, 
registers the class factories and then does not shut down.

	Stefan

> -----Original Message-----
> From: python-list-bounces+sschukat=dspace.de at python.org
> [mailto:python-list-bounces+sschukat=dspace.de at python.org]On Behalf Of
> xeoicq at netscape.net
> Sent: Monday, February 14, 2005 12:53 PM
> To: python-list at python.org
> Subject: keeping a COM server alive
> 
> 
> I have implemented a local COM Server with win32com framework 
> where all
> clients
> use the same global object (test_obj). So far it works, but when the
> last client
> is closed the gobal object is deleted because the pythonw.exe is
> closed. When I
> create a new client a new pythonw process is started. I need that the
> new client
> gets the same global object. How can I prevent the Python COM
> enviornment
> (pythonw.exe) to close when no client exist. I figured out a
> workaround, but
> there must be real solution to the problem.
> 
> 
> 
> The code looks like:
> 
> class test:
>     ...
> 
> test_obj=test()
> 
> 
> class test_F:
> 
>     _reg_clsid_ = ...
>     _reg_progid_ = "test.cl"
>     _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
>     _public_methods_ = ...
> 
> 
>     def __init__(self):
>         self.delegate=test_obj
>         ....
>     ...
> 
> 
> ####Workaround to keep the local server alive
> if not __name__=='__main__':
>     import win32com.client
>     dummy=win32com.client.Dispatch("test.cl")
> ##########################################################
> 
> 
> if __name__=='__main__':
>     import win32com.server.register
>     win32com.server.register.UseCommandLine(test_F, debug=0)
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list