[Python-ideas] Thread stopping

Michael Foord fuzzyman at gmail.com
Mon Apr 2 13:53:17 CEST 2012


On 30 March 2012 05:53, Eli Bendersky <eliben at gmail.com> wrote:

> On Thu, Mar 29, 2012 at 21:48, Andrew Svetlov <andrew.svetlov at gmail.com>wrote:
>
>> I propose to add Thread.interrupt() function.
>>
> <snip>
>
> Could you specify some use cases where you believe this would be better
> than explicitly asking the thread to stop?
>


What do you mean by "asking the thread to stop?". What is proposed is
precisely that. The usual suggestion is a flag, and have the thread check
if it has been "asked to stop". This is only suitable for fine grained
tasks (e.g. computationally bound loops) where there is a suitable place to
check. Any coarse grained task, or code with multiple loops for example,
may not have any place to check - or may need checking code in *many*
places.

One concrete example - at Resolver Systems we implemented a spreadsheet
application where multiple documents could be calculating simultaneously in
separate threads. (This was in IronPython with no GIL and true free
threading.) As we were executing *user code* there was no way for the code
to check if it had been requested to stop. (Unless we transformed the code
and annotated it with checks everywhere.) With .NET threads we could simply
request the thread to exit (if the user wanted to halt a calculation - for
example because they had updated the code / spreadsheet) and it worked very
well.

Thread interruption is a useful feature.

Michael



>
> Eli
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>


-- 

http://www.voidspace.org.uk/

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120402/f7e137b9/attachment.html>


More information about the Python-ideas mailing list