Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

killing own process in windows

12 views
Skip to first unread message

News123

unread,
Mar 7, 2010, 4:08:39 PM3/7/10
to
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

Martin P. Hellwig

unread,
Mar 7, 2010, 4:28:16 PM3/7/10
to

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.

--
mph

News123

unread,
Mar 7, 2010, 4:54:28 PM3/7/10
to
Hi Martin.

Hellwig wrote:
> On 03/07/10 21:08, News123 wrote:
>> 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
>>
>>
> 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

Martin P. Hellwig

unread,
Mar 7, 2010, 5:27:48 PM3/7/10
to

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 :-)

--
mph

Christian Heimes

unread,
Mar 7, 2010, 5:36:54 PM3/7/10
to pytho...@python.org
News123 wrote:
> 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()

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.

Christian

News123

unread,
Mar 7, 2010, 6:01:39 PM3/7/10
to
Hi Cristian,

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

0 new messages