<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 24, 2016 at 8:17 AM, Yury Selivanov <span dir="ltr"><<a href="mailto:yselivanov.ml@gmail.com" target="_blank">yselivanov.ml@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On 2016-08-23 10:38 PM, Rajiv Kumar wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was playing with your implementation to gain a better understanding of the operation of asend() and friends. Since I was explicitly trying to "manually" advance the generators, I wasn't using asyncio or other event loop. This meant that the first thing I ran into with my toy code was the RuntimeError ("cannot iterate async generator without finalizer set").<br>
<br>
As you have argued elsewhere, in practice the finalizer is likely to be set by the event loop. Since the authors of event loops are likely to know that they should set the finalizer, would it perhaps be acceptable to merely issue a warning instead of an error if the finalizer is not set? That way there isn't an extra hoop to jump through for simple examples.<br>
<br>
In my case, I just called<br>
sys.set_asyncgen_finalizer(lam<wbr>bda g: 1)<br>
to get around the error and continue playing :) (I realize that's a bad thing to do but it didn't matter for the toy cases)<br>
</blockquote>
<br></span>
Yeah, maybe warning would be sufficient. I just find it's highly unlikely that a lot of people would use async generators without a loop/coroutine runner, as it's a very tedious process.<br></blockquote></div><br></div><div class="gmail_extra">Heh, I had the same reaction as Rajiv. I think the tediousness is actually a good argument that there's no reason to forbid this. I don't even think a warning is needed. People who don't use a coroutine runner are probably just playing around (maybe even in the REPL) and they shouldn't get advice unasked.<br><br></div><div class="gmail_extra">Would it be possible to print a warning only when an async generator is being finalized and doesn't run straight to the end without suspending or yielding? For regular generators we have a similar exception (although I don't recall whether we actually warn) -- if you call close() and it tries to yield another value it is just GC'ed without giving the frame more control. For an async generator there are two cases: either it tries to yield another value (the first time this happens you can throw an error back into it) or it tries to await -- in that case you can also throw an error back into it, and if the error comes out unhandled you can print the error (in both cases actually).<br><br></div><div class="gmail_extra">It's probably to specify all this behavior using some kind of default finalizer (though you don't have to implement it that way).<br><br></div><div class="gmail_extra">Hopefully there will be other discussion as well, otherwise I'll have to accept the PEP once this issue is cleared up. :-)<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>