summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-24 20:37:53 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-24 20:37:53 (GMT)
commita02f81ff1757a257c7243ff53542d6f4f34668db (patch)
treeca6cbc226160469f0d16622f308ca88ee68aec1a /Lib/asyncio
parent4c945fe9e9ea813ecb19ed705e1c7b3ae26b0d2a (diff)
downloadcpython-a02f81ff1757a257c7243ff53542d6f4f34668db.zip
cpython-a02f81ff1757a257c7243ff53542d6f4f34668db.tar.gz
cpython-a02f81ff1757a257c7243ff53542d6f4f34668db.tar.bz2
asyncio: Log an error if a Task is destroyed while it is still pending
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/futures.py3
-rw-r--r--Lib/asyncio/tasks.py13
2 files changed, 16 insertions, 0 deletions
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index 91ea170..4edd2e5 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -169,6 +169,9 @@ class Future:
res += '<{}>'.format(self._state)
return res
+ # On Python 3.3 or 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 _PY34:
def __del__(self):
if not self._log_traceback:
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index eaf93f8..f5c10c8 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -32,6 +32,7 @@ from .log import logger
_DEBUG = (not sys.flags.ignore_environment
and bool(os.environ.get('PYTHONASYNCIODEBUG')))
+_PY34 = (sys.version_info >= (3, 4))
_PY35 = (sys.version_info >= (3, 5))
@@ -181,6 +182,18 @@ class Task(futures.Future):
self._loop.call_soon(self._step)
self.__class__._all_tasks.add(self)
+ # On Python 3.3 or 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 _PY34:
+ def __del__(self):
+ if self._state == futures._PENDING:
+ self._loop.call_exception_handler({
+ 'task': self,
+ 'message': 'Task was destroyed but it is pending!',
+ })
+ futures.Future.__del__(self)
+
def __repr__(self):
res = super().__repr__()
if (self._must_cancel and