[issue24795] Make event loops with statement context managers

2017-12-20 Thread Andrew Svetlov
Andrew Svetlov added the comment: Superseded by `asyncio.run()` function. P.S. Context manager is not a solution because `loop.shutdown_asyncgens()` should be called before `loop.close()` and the method is a coroutine. -- nosy: +asvetlov resolution: -> wont fix stage: -> resolved st

[issue24795] Make event loops with statement context managers

2015-08-06 Thread Guido van Rossum
Guido van Rossum added the comment: My worry is that the context manager will make people believe it's a good pattern to create an event loop just to make one call. If tests violate this pattern, add a context manager helper function to test_utils.py. On Thu, Aug 6, 2015 at 2:57 AM, Martin Pante

[issue24795] Make event loops with statement context managers

2015-08-05 Thread Martin Panter
Martin Panter added the comment: >From what I can see, the examples in the current documentation tend to diectly >call loop.close() without an exception handler. Only two examples have the >bare-bones try / finally handler (which is important for the example that uses >Ctrl+C). -- nos

[issue24795] Make event loops with statement context managers

2015-08-05 Thread STINNER Victor
STINNER Victor added the comment: +1 for me. Asyncio examples already have this try/finally pattern. I already proposed to support context manager some months ago. Guido, I don't understand your point. Usually the main function id loop.run_until_complete/.run_forever. That's all. It doesn't mean

[issue24795] Make event loops with statement context managers

2015-08-05 Thread Guido van Rossum
Guido van Rossum added the comment: This seems the wrong idea to me. Event loops should be long-lived, so the context manager would ideally see very little use. -- ___ Python tracker ___

[issue24795] Make event loops with statement context managers

2015-08-05 Thread Mathias Fröjdman
Mathias Fröjdman added the comment: (Just noticed http://bugs.python.org/issue19860, which I originally failed to notice when just searching for "asyncio loop" and not context manager) Anyway, in recent Python/asyncio versions, failing to close the event loop before exiting whole the process c

[issue24795] Make event loops with statement context managers

2015-08-05 Thread Mathias Fröjdman
New submission from Mathias Fröjdman: 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