[issue31520] ResourceWarning: unclosed <socket.socket [closed] fd=3, ...> warning

STINNER Victor report at bugs.python.org
Mon Sep 25 05:29:01 EDT 2017


STINNER Victor added the comment:

socket.SocketIO inherits from io.RawIOBase which inherits from io.IOBase.

io.IOBase has a finalizer which calls the close() method. I tried to add a __del__ method to socket.SocketIO, but the object was already closed by the finalizer.

io.FileIO uses a trick at the C level: it sets an internal "finalizing" attribute to check if close() was called by IOBase finalizer. If it's the case, a ResourceWarning is emitted.

I don't see a simpler way to emit a ResourceWarning in SocketIO. Maybe it's not the right approach.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31520>
_______________________________________


More information about the Python-bugs-list mailing list