This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Mathias Fröjdman
Recipients Mathias Fröjdman, gvanrossum, vstinner, yselivanov
Date 2015-08-05.12:38:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1438778311.28.0.548352526709.issue24795@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2015-08-05 12:38:34Mathias Fröjdmansetrecipients: + Mathias Fröjdman, gvanrossum, vstinner, yselivanov
2015-08-05 12:38:31Mathias Fröjdmansetmessageid: <1438778311.28.0.548352526709.issue24795@psf.upfronthosting.co.za>
2015-08-05 12:38:28Mathias Fröjdmanlinkissue24795 messages
2015-08-05 12:38:24Mathias Fröjdmancreate