[Python-ideas] Hooks into the IO system to intercept raw file reads/writes

Victor Stinner victor.stinner at gmail.com
Tue Feb 10 14:42:21 CET 2015


Hi,

2015-02-04 21:21 GMT+01:00 Greg Ewing <greg.ewing at canterbury.ac.nz>:
> Paul Moore wrote:
>>
>> ... found it. You need loop.close() at the end. Maybe the loop object
>> should close itself in the __del__ method, like file objects?

In the latest version of asyncio, there are now destructors on event
loops and transports on Python 3.4+. The destructor closes the event
loop/transport, but also emit a ResourceWarning warning because it's
not safe to rely on destructors. The destructor may be called too
late. For example, closing a transport may need a running event loop.
Subprocess is a good example of complex transport.

> Yeah, this looks like a bug -- I didn't notice anything
> in the docs about it being mandatory to close() a loop
> when you're finished with it, and such a requirement
> seems rather unpythonic.

In the latest section of the asyncio doc, I added recently:
"ResourceWarning warnings are emitted when transports and event loops
are not closed explicitly."
https://docs.python.org/dev/library/asyncio-dev.html#develop-with-asyncio

I also added a section dedicated to closing event loops and transports:
https://docs.python.org/dev/library/asyncio-dev.html#close-transports-and-event-loops

Maybe I should repeat the information somewhere else in the documentation?

Victor


More information about the Python-ideas mailing list