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 vstinner
Recipients gvanrossum, pitrou, vstinner
Date 2013-12-02.11:45:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1385984759.42.0.47454056153.issue19860@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-12-02 11:45:59vstinnersetrecipients: + vstinner, gvanrossum, pitrou
2013-12-02 11:45:59vstinnersetmessageid: <1385984759.42.0.47454056153.issue19860@psf.upfronthosting.co.za>
2013-12-02 11:45:59vstinnerlinkissue19860 messages
2013-12-02 11:45:59vstinnercreate