Message248032
Since asyncio event loops have to be closed nowadays, it would be pretty convenient and pythonic to make BaseEventLoop a context manager that calls self.close() in __exit__ the same way as contextlib.closing() does it. Example:
import asyncio
with asyncio.get_event_loop() as loop:
loop.run_until_complete(func())
instead of
import asyncio
from contextlib import closing
with closing(asyncio.get_event_loop()) as loop:
loop.run_until_complete(func())
or event the bulkier
import asyncio
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(func())
finally:
loop.close()
The attached patch applies to Python 3.5b4's asyncio/base_events.py |
|
Date |
User |
Action |
Args |
2015-08-05 12:38:34 | Mathias Fröjdman | set | recipients:
+ Mathias Fröjdman, gvanrossum, vstinner, yselivanov |
2015-08-05 12:38:31 | Mathias Fröjdman | set | messageid: <1438778311.28.0.548352526709.issue24795@psf.upfronthosting.co.za> |
2015-08-05 12:38:28 | Mathias Fröjdman | link | issue24795 messages |
2015-08-05 12:38:24 | Mathias Fröjdman | create | |
|