<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div name="messageBodySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;">One of the design decisions about `loop.close()` is that it doesn't
<div>do a single event loop iteration, making its behaviour highly predictable.</div>
<div>To make `loop.close()` to run `loop.shutdown_asyncgens()` (which is a </div>
<div>coroutine), we would have needed to change that.</div>
<div><br /></div>
<div>One of the ways we want to mitigate this problem in Python 3.7 is to</div>
<div>add a new function to bootstrap asyncio and run top-level coroutines:</div>
<div>`asyncio.run()`.  You can read more about it here: [1].</div>
<div><br /></div>
<div>I'm working on a new PEP that will summarize asyncio changes in 3.7.</div>
<div>I don't have a concrete ETA for it, but I'll try to get the first draft out</div>
<div>by mid September.</div>
<div><br /></div>
<div>[1] https://github.com/python/asyncio/pull/465</div>
</div>
<div name="messageSignatureSection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
Thanks,<br />
Yury</div>
<div name="messageReplySection" style="font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, sans-serif;"><br />
On Jul 27, 2017, 11:24 PM -0400, Chris Jerdonek <chris.jerdonek@gmail.com>, wrote:<br />
<blockquote type="cite" style="margin: 5px 5px; padding-left: 10px; border-left: thin solid #1abc9c;">I have a question about PEP 525 (Asynchronous Generators) which I'm<br />
sure has a simple answer, but I didn't see it in the PEP or final<br />
discussion:<br />
https://mail.python.org/pipermail/python-dev/2016-September/146265.html<br />
<br />
Basically, why is the API such that loop.shutdown_asyncgens() must be<br />
called manually? For example, why can't it be called automatically as<br />
part of close(), which seems like it would be a friendlier API and<br />
more helpful to the common case?<br />
<br />
I was trying asynchronous iterators in my code and getting the following error:<br />
<br />
Exception ignored in: <generator object Queue.get at 0x7f950a667678<br />
Traceback (most recent call last):<br />
File "/usr/local/lib/python3.6/asyncio/queues.py", line 169, in get<br />
getter.cancel() # Just in case getter is not done yet.<br />
File "/usr/local/lib/python3.6/asyncio/base_events.py", line<br />
574, in call_soon<br />
self._check_closed()<br />
File "/usr/local/lib/python3.6/asyncio/base_events.py", line<br />
357, in _check_closed<br />
raise RuntimeError('Event loop is closed')<br />
RuntimeError: Event loop is closed<br />
<br />
Calling loop.shutdown_asyncgens() made the error go away, but it seems<br />
a little obscure that by adding an asynchronous iterator somewhere in<br />
your code, you have to remember to check that that line is present<br />
before loop.close() is called (and the exception message doesn't<br />
provide a good hint).<br />
<br />
Is there any disadvantage to always calling loop.shutdown_asyncgens()<br />
(i.e. even if it's not needed)? And why might someone need to call it<br />
at a different time?<br />
<br />
Thanks,<br />
--Chris<br />
_______________________________________________<br />
Async-sig mailing list<br />
Async-sig@python.org<br />
https://mail.python.org/mailman/listinfo/async-sig<br />
Code of Conduct: https://www.python.org/psf/codeofconduct/<br /></blockquote>
</div>
</body>
</html>