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 <rep...@bugs.python.org>
<http://bugs.python.org/issue19860>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to