killing own process in windows

N

News123

Hi,


How can I kill my own process?

Some multithreaded programs, that I have are unable to stop when ctrl-C
is pressed.
Some can't be stopped with sys.exit()

So I'd just like to terminate my own program.


Examples of non killable (not killable with CTRL-C) programs:
- A program, that started an XMLRPC server with serve_forever
- a program, that started a multiprocessing.Manager with serve_forever


thanks in advance for some ideas.


N
 
M

Martin P. Hellwig

Hi,


How can I kill my own process?

Some multithreaded programs, that I have are unable to stop when ctrl-C
is pressed.
Some can't be stopped with sys.exit()

So I'd just like to terminate my own program.


Examples of non killable (not killable with CTRL-C) programs:
- A program, that started an XMLRPC server with serve_forever
- a program, that started a multiprocessing.Manager with serve_forever


thanks in advance for some ideas.


N

If it is just the xml rpc server you want to kill, there might be better
ways. For example look at:
http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py
with perhaps special interest at the comment on lines 172-174.
 
N

News123

Hi Martin.
Hellwig said:
If it is just the xml rpc server you want to kill, there might be better
ways. For example look at:
http://code.google.com/p/dcuktec/source/browse/source/wrapped_xmlrpc_server/rpc.py

with perhaps special interest at the comment on lines 172-174.
I



Thanks. this looks like a good solution for an XMLRPC server.
However when playing with different server modules I fall over and over
again over code, that can't be shutdown nicely.

Currently I'm still struggling with multiprocessing.managers,BaseManager

bye

N
 
M

Martin P. Hellwig

Hi Martin.

I



Thanks. this looks like a good solution for an XMLRPC server.
However when playing with different server modules I fall over and over
again over code, that can't be shutdown nicely.

Currently I'm still struggling with multiprocessing.managers,BaseManager

bye

N

I haven't used the multiprocessing module yet, but generally speaking I
believe that everything in python that is server-like inherits from
SocketServer BaseServer. Probably for you to have all servers behave in
a way you expect, is to override functionality there, for example in:
http://docs.python.org/library/socketserver.html?highlight=baseserver#SocketServer.BaseServer
the function: handle_request

Though from looking at the source the function serve_forever is just an
while loop over handle request (blocking or no-blocking), so might be a
better candidate to replace.

But you still might find that some tcp connections remain open, so
unless you want to go down to the socket level and explicit close the
socket, there is not much you can do about that.

For the client side, socket timeout is you enemy, I found something
rather long as default (300 seconds in the xml-rpc client) but yours
might be different (it is probably a Python defined standard default,
but I haven't checked that).

Sounds to me like you will be busy reading up on it now :)

Oh and just a word to prevent over-engineering, if both the server and
client is written by you, a lot of problems you anticipate will probably
never occur because that would require a rogue server or client. Unless
of course you like making rogue server/clients :)
 
N

News123

Hi Cristian,

Christian said:
You have to terminate the XMP-RPC server or the manager first. Check the
docs!

You can terminate a Python process with os._exit() but I recommend that
you find another way. os._exit() is a hard termination. It kills the
process without running any cleanup code like atexit handlers and
Python's internal cleanups. Open files aren't flushed to disk etc.

This is exactly the problem:
Neither the XMLRPC server nor the manager can be stopped
both serve forever. The doc doesn't really help.

For the XMLRPC server there are tricks to subclass it and to change the
behaviour, as indicated by Martin.

for the manager I did not find a clean solution (Plese see my other
thread "stopping a multiprocessing.manage.....")


I'm surprised, that there are no 'canned' solution to stop servers
remotely or just by pressing ctrl-C
I consider this being quite useful for certain kinds of applications.

I prefer to ask a server to shutdown, than to just kill him.

Am interactive program, which also acts like a server should be able
to shutdown its server thread from the main thread in order to quit nicely.


Baseserver has even a shutdown method(), but it cannot be called if
were started with serve_forever().

N
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top