From: News123 on
Hi Cristian,

Christian Heimes wrote:
> 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.
>

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