is it safe to stop a thread?
Dustin Boswell
boswell at ugcs.caltech.edu
Wed May 23 01:35:53 EDT 2001
Woa, I was way off. I got confused into thinking a thread could stop another. Not
true.
Yes, and I totally agree with you that there should be some "safe" mechanism set
up for threads to signal each other. But why is it safe to stop a process? Unix gives
you the option of CTRL-C'ing it, so obviously it must be somewhat safe (even if
its busy doing file i/o, or otherwise using resources, which is a common argument
for not allowing programmers to stop threads.)
It seems like I'm being forced to do multiple processes and interprocess-communication,
which seems dumb, cause threading seems like a better solution...
Parzival Herzog wrote:
> "Dustin Boswell" <boswell at ugcs.caltech.edu> wrote in message news:3B0AFDEF.44E29573 at ugcs.caltech.edu...
> > The "threading" module doesn't allow stopping, so that seems useless.
> > But the "thread" module DOES
>
> It DOES? How? the docs I have say that a thread can stop ITSELF, by
> raising SystemExit, or calling sys.exit(). But nowhere
> have I seen the ability for one thread to stop a
> another thread. Please correct me if I'm wrong,
> I would certainly be happy if I was wrong and
> threads could be stopped.
>
> Past posts on this group have suggested that the
> subject thread should poll for an indication
> that it should stop itself, and that one thread
> trying to stop another thread from another is
> a sign of poor design.
>
> I would disagree, and ask if anyone can offer a
> more rational explanation why Python threads
> are designed to be not stoppable (if I am not
> mistaken about this.)
>
> Polling for a "stop" indication cannot be
> done reliably for any thread using code not written
> by the programmer who wants to achieve a reliable stop:
> The thread may block, or call some library code
> that is not under the programmer's control that
> fails to poll, or blocks without the programmer's
> knowledge. Even for the code that is under the
> programmers control, it can be difficult to
> design arbitrary algorithms that always poll,
> and such coding certainly is more difficult to
> understand an maintain.
>
> IMHO, it would be far better, if as in Modula-3,
> one thread could "alert" another thread, thereby
> raising an "alerted" exception in that thread, which
> if not caught and otherwise dealt with would end that
> thread.
>
> - Parzival
More information about the Python-list
mailing list