[Python-ideas] Thread stopping
Yury Selivanov
yselivanov.ml at gmail.com
Fri Mar 30 01:10:43 CEST 2012
On 2012-03-29, at 6:56 PM, Michael Foord wrote:
> I've worked with .NET where you can interrupt threads and it was very useful. There is a complication though, if a thread is interrupted inside a finally block then vital resource cleanup can be interrupted. The way .NET solves this is to never raise the interrupt exception inside a finally block. Once a finally block is completed a pending thread interrupt exception will be raised.
That's the same problem we had in our coroutine framework (based on
generators + greenlets). We've decided to modify the __code__ object
of generators and add a simple counter of finally statements, and when
it reaches 0 - call a special callback that checks if the interruption
exception should be raised.
Much cleaner way would be to embed this functionality in the python
interpreter itself, but I'm not sure about the performance impact.
-
Yury
More information about the Python-ideas
mailing list