Nathaniel Smith <n...@pobox.com> added the comment:
Part of the issue here is the one discussed in bpo-30773 / bpo-32526: async 
generators allow themselves to be re-entered while another asend/athrow/aclose 
call is in progress, and it causes weird and confusing results. So at a 
minimum, trying to call aclose while another task is calling asend should make 
aclose raise an error saying that the generator is already busy.

Of course the OP wants to go further and have aclose actually trigger a 
cancellation of any outstanding asend/athrow. I see the intuition here, but 
unfortunately I don't think this can work. Doing a cancellation requires some 
intimate knowledge of the coroutine runner. You can't just throw in an 
exception; you also have to unwind the task state. (Eg in the example with 
'event.wait', you need to somehow tell the event object that this task is no 
longer waiting for it, so it shouldn't be notified when the event occurrs.)

So I think we just need to fix ag_running and then recommend people find other 
ways to interrupt running async generators.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34730>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to