27 Oct
2012
27 Oct
'12
6:21 p.m.
Guido van Rossum wrote:
The example would have to set some flag indicating it has a result after the first yield (i.e. before entering the finally, or at least before yielding in the finally clause). And the timeout callback would have to check this flag. This makes it slightly awkward to design a general-purpose timeout mechanism for tasks written in this style -- if you expect a timeout or cancellation you must protect your cleanup code from it by using some API.
This is where having a way to find out whether a generator is in a finally clause would help. It would allow the scheduler to take care of this transparently. -- Greg