threading questions
Martin v. Loewis
martin at v.loewis.de
Fri Nov 1 17:12:57 EST 2002
Oleg Leschov <kalmas at udm.ru> writes:
> 1. I want to be able, using whatever the threading.get_ident()
> returns (perhaps), to determine the state of thread (does it still
> run or not), and to kill the thread, in case that it, for example,
> is waiting for some data from socket whose network interface has
> died unexpectedly.
Python does not support thread cancellation.
> For now I rely on the behavior of linux, where when main thread
> quits, all its children threads are also being killed. But to me, it
> would be nicer to kill them by hand..
You would need to implement this yourself, although I recommend to
find a solution that works without that. I.e. maintain a list of
running threads yourself, and you won't need to find out whether a
thread is still running. Only use non-blocking operations for the
network if you expect blocking operations to block for an unacceptable
long amount of time.
> 2. I want to process user interrupt (ctrl-c), which does not work at
> all while running multiple threads, by setting some event so that
> main thread would quit. How do I register handler for this?
Ctrl-c should work fine, and should show up as a keyboard interrupt in
the main thread.
Regards,
Martin
More information about the Python-list
mailing list