Stopping a python thread
Ulrich Berning
berning at teuto.de
Thu Oct 19 06:50:06 EDT 2000
Aahz Maruch wrote:
> What do you need to do this for? The standard response is that the
> spawned thread should determine when it should stop processing work and
> execute a "return". That will kill the thread automatically. There are
> a variety of ways of signalling the thread to exit.
If the spawned thread blocks in a system call like read() or write() there is no
way to tell the thread to stop working.
Therefore the pthreads standard defines a number of system calls that must be
defined as cancellation points
e.g. read(), write(), open(), creat(), wait(), ...
With a call to pthread_cancel() you can tell a thread to stop working even if it
hangs in such a blocking call.
Cancellation is a missing feature in the python threads implementation I think.
Without cancellation, there is no chance
to write multithreaded servers in python that can do a clean shutdown with the
possibility to call cleanup handlers
for every canceled thread.
---
Ulli Berning
More information about the Python-list
mailing list