Terminating a local process COM server

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri Jun 29 04:33:01 EDT 2001

"Steve Holden" <sholden at holdenweb.com> wrote in
news:R4R_6.6433$Gf4.286144 at e420r-atl1.usenetserver.com: 

> For efficiency reasons I am implementing a credit-card checking
> algorithm as a COM LocalServer object.
> For debugging purposes I would like to be able to terminate the current
> instantiation (i.e. process), so I can start another one with revised
> Python code. It would also be nice, in production, to have some way to
> terminate the LocalServer process so that the next instantiation of the
> COM object restarts the server in a new process.
> I'm aware that this would invalidate references to any objects created
> by the process, but for testing it *would* be "comvenient" not to have
> to kill the COM server process manually.
> Anyone help? Or at least explain where I'm mistaken if this isn't a
> sensible goal...
In principle you could query the registry to work out the name of the EXE 
file and then find the relevant process and kill it. In practice this gets 
difficult if you find more than one matching EXE file: this is especially a 
problem with COM objects written in Python, as there are quite likely to be 
other Python or PythonW processes lying around.

Another option would be to put the COM object into an NT service. That way 
you can simply stop and start the service at will. I recently wrote a 
service containing a COM object, let me know if you want a copy of the 
code. The downside to this is that it makes it harder to debug the service 
when things go wrong.

Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list