Stopping threads from the outside

Peter Hansen peter at engcorp.com
Sun Mar 24 13:13:14 EST 2002


holger at trillke.net wrote:
> 
> > >how could you stop a running threading.Thread from the *outside*? of
> > >course i could introduce some kind of flag into the event loop of the
> > >Thread.run-method, but i really would prefer to have a non-instrusive
> > >way for several reasons.
> > >
> > >Any way to do this?
> >
> > Not really.  Why do you want to do it?
> 
> You really want to know it? I am currently working
> on (coded) agents which move through the network.

"The network"?  Which one?  The Internet, or an internal
network over which you have full control?  Who controls
the servers on which these agents will be running?

> But of course i'd sometimes like to shut down some or
> all agent-threads. 

Run them in a separate process and kill the process when
it's "sometime"?  If you can live without individual
control.  Maybe you can identify groups of them?

> Is the questions actually strange in any way? Like something
> you wouldn't usually like to do?

Yes, that's the case.  It's generally considered to lead to
undefined behaviour if you do manage to kill a thread from 
the outside, because of resource locking issues and such.

Maybe you can get by with Stackless Python?  The microthreads
provided there ought to be more easily killable, though 
I haven't tried it myself.

-Peter



More information about the Python-list mailing list