Issue #23243, asyncio: Emit a ResourceWarning when an event loop or a transport

is not explicitly closed. Close also explicitly transports in test_sslproto.
This commit is contained in:
Victor Stinner 2015-01-29 17:50:58 +01:00
parent 3c0cf05901
commit 978a9afc6a
10 changed files with 104 additions and 10 deletions

View file

@ -8,6 +8,7 @@ import stat
import subprocess
import sys
import threading
import warnings
from . import base_events
@ -353,6 +354,15 @@ class _UnixReadPipeTransport(transports.ReadTransport):
if not self._closing:
self._close(None)
# On Python 3.3 and older, objects with a destructor part of a reference
# cycle are never destroyed. It's not more the case on Python 3.4 thanks
# to the PEP 442.
if sys.version_info >= (3, 4):
def __del__(self):
if self._pipe is not None:
warnings.warn("unclosed transport %r" % self, ResourceWarning)
self._pipe.close()
def _fatal_error(self, exc, message='Fatal error on pipe transport'):
# should be called by exception handler only
if (isinstance(exc, OSError) and exc.errno == errno.EIO):
@ -529,6 +539,15 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
# write_eof is all what we needed to close the write pipe
self.write_eof()
# On Python 3.3 and older, objects with a destructor part of a reference
# cycle are never destroyed. It's not more the case on Python 3.4 thanks
# to the PEP 442.
if sys.version_info >= (3, 4):
def __del__(self):
if self._pipe is not None:
warnings.warn("unclosed transport %r" % self, ResourceWarning)
self._pipe.close()
def abort(self):
self._close(None)