[New-bugs-announce] [issue19860] asyncio: Add context manager to BaseEventLoop?

STINNER Victor report at bugs.python.org
Mon Dec 2 12:45:59 CET 2013


New submission from STINNER Victor:

The BaseSelectorEventLoop class (inherited by UnixSelectorEventLoop) creates a socketpair in its constructor. So if you don't call close(), the socketpair may stay alive.

It would be convinient to support the context manager to be able to write:

with asyncio.get_event_loop() as loop
   # ... prepare loop ...
   loop.run_forever()
# KeyboardInterrupt or SystemExit: loop.close() is called

Hello World examples don't call close(), so the sockets are not closed when the example is stopped using CTRL+c.

Attached patch adds __enter__/__exit__ methods to BaseEventLoop and use it in the two Hello World examples.

----------
files: eventloop_context_manager.patch
keywords: patch
messages: 205004
nosy: gvanrossum, haypo, pitrou
priority: normal
severity: normal
status: open
title: asyncio: Add context manager to BaseEventLoop?
versions: Python 3.4
Added file: http://bugs.python.org/file32936/eventloop_context_manager.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19860>
_______________________________________


More information about the New-bugs-announce mailing list