Hi, I've updated PEP 525 with a new section about asyncio changes. Essentially, asyncio event loop will get a new "shutdown_asyncgens" method that allows to close the loop and all associated AGs with it reliably. Only the updated section is pasted below: asyncio ------- The asyncio event loop will use ``sys.set_asyncgen_hooks()`` API to maintain a weak set of all scheduled asynchronous generators, and to schedule their ``aclose()`` coroutine methods when it is time for generators to be GCed. To make sure that asyncio programs can finalize all scheduled asynchronous generators reliably, we propose to add a new event loop method ``loop.shutdown_asyncgens(*, timeout=30)``. The method will schedule all currently open asynchronous generators to close with an ``aclose()`` call. After calling the ``loop.shutdown_asyncgens()`` method, the event loop will issue a warning whenever a new asynchronous generator is iterated for the first time. The idea is that after requesting all asynchronous generators to be shutdown, the program should not execute code that iterates over new asynchronous generators. An example of how ``shutdown_asyncgens`` should be used:: try: loop.run_forever() # or loop.run_until_complete(...) finally: loop.shutdown_asyncgens() loop.close() - Yury
Thanks Yury!
I am hereby accepting PEP 525 provisionally. The acceptance is so that
you can go ahead and merge this into 3.6 before the feature freeze
this weekend. The provisional status is because this is a big project
and it's likely that we'll need to tweak some small aspect of the API
once the code is in, even after 3.6.0 is out. (Similar to the way PEP
492, async/await, was accepted provisionally.) But I am cautiously
optimistic and I am grateful to Yury for the care and effort he has
put into it.
--Guido
On Tue, Sep 6, 2016 at 5:10 PM, Yury Selivanov
Hi,
I've updated PEP 525 with a new section about asyncio changes.
Essentially, asyncio event loop will get a new "shutdown_asyncgens" method that allows to close the loop and all associated AGs with it reliably.
Only the updated section is pasted below:
asyncio -------
The asyncio event loop will use ``sys.set_asyncgen_hooks()`` API to maintain a weak set of all scheduled asynchronous generators, and to schedule their ``aclose()`` coroutine methods when it is time for generators to be GCed.
To make sure that asyncio programs can finalize all scheduled asynchronous generators reliably, we propose to add a new event loop method ``loop.shutdown_asyncgens(*, timeout=30)``. The method will schedule all currently open asynchronous generators to close with an ``aclose()`` call.
After calling the ``loop.shutdown_asyncgens()`` method, the event loop will issue a warning whenever a new asynchronous generator is iterated for the first time. The idea is that after requesting all asynchronous generators to be shutdown, the program should not execute code that iterates over new asynchronous generators.
An example of how ``shutdown_asyncgens`` should be used::
try: loop.run_forever() # or loop.run_until_complete(...) finally: loop.shutdown_asyncgens() loop.close()
- Yury _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido)
Thank you, Guido! I've updated the PEP to make shutdown_asyncgens a coroutine, as we discussed. Yury On 2016-09-06 7:10 PM, Guido van Rossum wrote:
Thanks Yury!
I am hereby accepting PEP 525 provisionally. The acceptance is so that you can go ahead and merge this into 3.6 before the feature freeze this weekend. The provisional status is because this is a big project and it's likely that we'll need to tweak some small aspect of the API once the code is in, even after 3.6.0 is out. (Similar to the way PEP 492, async/await, was accepted provisionally.) But I am cautiously optimistic and I am grateful to Yury for the care and effort he has put into it.
--Guido
On Tue, Sep 6, 2016 at 5:10 PM, Yury Selivanov
wrote: Hi,
I've updated PEP 525 with a new section about asyncio changes.
Essentially, asyncio event loop will get a new "shutdown_asyncgens" method that allows to close the loop and all associated AGs with it reliably.
Only the updated section is pasted below:
asyncio -------
The asyncio event loop will use ``sys.set_asyncgen_hooks()`` API to maintain a weak set of all scheduled asynchronous generators, and to schedule their ``aclose()`` coroutine methods when it is time for generators to be GCed.
To make sure that asyncio programs can finalize all scheduled asynchronous generators reliably, we propose to add a new event loop method ``loop.shutdown_asyncgens(*, timeout=30)``. The method will schedule all currently open asynchronous generators to close with an ``aclose()`` call.
After calling the ``loop.shutdown_asyncgens()`` method, the event loop will issue a warning whenever a new asynchronous generator is iterated for the first time. The idea is that after requesting all asynchronous generators to be shutdown, the program should not execute code that iterates over new asynchronous generators.
An example of how ``shutdown_asyncgens`` should be used::
try: loop.run_forever() # or loop.run_until_complete(...) finally: loop.shutdown_asyncgens() loop.close()
- Yury _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org
Thanks Yury! (Everyone else following along, the PEP is accepted provisionally, and we may make small tweaks from time to time during Python 3.6's lifetime.)
participants (2)
-
Guido van Rossum
-
Yury Selivanov