summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-29 16:50:58 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-01-29 16:50:58 (GMT)
commit978a9afc6af6c137065bdcf7ae4ef5450e5b2ec2 (patch)
tree54eb1a4cdf09be18b62c40e0e203a347c37c4cd6 /Lib/asyncio/base_events.py
parent3c0cf05901ea5cca0694734fd4a64b2bc267cb41 (diff)
downloadcpython-978a9afc6af6c137065bdcf7ae4ef5450e5b2ec2.zip
cpython-978a9afc6af6c137065bdcf7ae4ef5450e5b2ec2.tar.gz
cpython-978a9afc6af6c137065bdcf7ae4ef5450e5b2ec2.tar.bz2
Issue #23243, asyncio: Emit a ResourceWarning when an event loop or a transport
is not explicitly closed. Close also explicitly transports in test_sslproto.
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index e40d3ad..7108f25 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -26,6 +26,7 @@ import threading
import time
import traceback
import sys
+import warnings
from . import coroutines
from . import events
@@ -333,6 +334,16 @@ class BaseEventLoop(events.AbstractEventLoop):
"""Returns True if the event loop was closed."""
return self._closed
+ # 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 not self.is_closed():
+ warnings.warn("unclosed event loop %r" % self, ResourceWarning)
+ if not self.is_running():
+ self.close()
+
def is_running(self):
"""Returns True if the event loop is running."""
return (self._owner is not None)