Killing a running thread

Alex Martelli aleax at aleax.it
Fri May 3 03:29:32 EDT 2002


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.


Alex




More information about the Python-list mailing list