Hi Thomas, thanks for your quick reply.
I think IClassFactory.LockServer is exactly what I'm looking for. However, I do not know how, when and where I should be able to access this method. I checked the sources and found that the factory instance gets lost somewhere in COMObject. I tried to do a factory = self.QueryInterface(comtypes.server.IClassFactory) factory.LockServer(None, True) inside the com server constructor but I get a COMError "Interface not supported". Then I tried the same with a client object of the server with the same result. According to the MS specs, I should use CoGetClassObject to obtain an IClassFactory instance. So I tried >>> factory = comtypes.CoGetClassObject(comtypes.GUID('{MY-GUID}')) >>> factory.LockServer(True) # btw: LockServer(None,True) returns a TypeError 0 Now I can create and close clients without the server shutting down. However, when I free the factory instance: >>> factory = None ...the server stops. That is not big improvement compared to creating a dummy client to keep the server alive because using the factory in the above way would also require a separate python process running keeping the factory instance alive. Probably I'm just doing it wrong... So What is the correct way to lock the server without the need of a second process running? Thanks! > -----Ursprüngliche Nachricht----- > Von: Thomas Heller [mailto:thel...@ctypes.org] > Gesendet: Mittwoch, 11. April 2012 21:14 > An: comtypes-users@lists.sourceforge.net > Betreff: Re: [comtypes-users] How to keep-alive a COM server without clients > connected? > > Am 11.04.2012 09:59, schrieb Jan Wedel: > > Hi, > > > > what ist he best way to keep-alive a COM server? The python > > application does more stuff in the background that needs to keep > > running. I know I can start the server without COM clients by using the "- > embedding" > > command line argument. However, as soon as the last COM client > > disconnects, the server stops. > > > > I could just write a one-line COM dummy client that keeps at least one > > connection open to the server but that would be an ugly way to solve > > the problem. > > > > There are some C++ based COM server that register as a windows service > > and I know that can be done with python as well. The question is if > > comtypes supports keeping the server responsive to COM clients even if > > no clients are connected at the moment? > > > > In the sources I found a Lock() method of LocalServer class in > > "_comobject.py" but I don't know if this really helps and I couldn't > > find any examples/test that show how to use it. > > Yes, factory.LockServer(None, True) will add a lock that keeps the server > running, factory.LockServer(None, False) will remove this lock again. > > http://msdn.microsoft.com/en- > us/library/windows/desktop/ms682332%28v=vs.85%29.aspx > > Thomas > > > ------------------------------------------------------------------------ ------ > Better than sec? Nothing is better than sec when it comes to monitoring Big > Data applications. Try Boundary one-second resolution app monitoring today. > Free. > http://p.sf.net/sfu/Boundary-dev2dev > _______________________________________________ > comtypes-users mailing list > comtypes-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/comtypes-users ------------------------------------------------------------------------------ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2 _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users