Killing a running thread

holger krekel pyth at devel.trillke.net
Fri May 3 04:58:43 EDT 2002


On Fri, May 03, 2002 at 07:29:32AM +0000, Alex Martelli wrote:
> Alexander Skwar wrote:
> 
> > ?Alex Martelli? sagte am 2002-05-02 um 15:32:48 +0000 :
> >> try:
> >>     map(myfunction, somehumongoushugelist)
> >> except OuttaHere:
> >>     pass
> > 
> > Yes, this idea also occured to me.  If I'm not mistaken, this should
> > break out of the map, no?
> 
> Yep!  Indeed, if your map is called within some other function
> etc, you may move the try/except statement outwards as much
> as you want -- every intermediate level of call will also terminate
> (with try/finally statements executing their finalizers as you pop).
> 
> Some people dislike this use of exceptions, but I think it's quite
> Pythonic and useful.

yes. To just warmup an idea posted a couple of thousand postings ago:
the interpreter could be instructed from outside a thread
to throw an exception when next running bytecode inside a certain thread
(called something like ThreadCanceledException or so). This 
doesn't work when the thread remains for a long time in C-Land, i guess.
But otherwise it still *seems* like a good idea to me.

  holger





More information about the Python-list mailing list