]> granicus.if.org Git - python/commitdiff
asyncio: Initialize more Future and Task attributes in the class definition to
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 4 Dec 2014 22:00:13 +0000 (23:00 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 4 Dec 2014 22:00:13 +0000 (23:00 +0100)
avoid attribute errors in destructors.

Lib/asyncio/futures.py
Lib/asyncio/tasks.py

index 19e79189dc25e492a385251fcc8437a7f5ca80f4..f46d008f08a113da0c4e35b7491156391a2d33cf 100644 (file)
@@ -135,6 +135,7 @@ class Future:
     _result = None
     _exception = None
     _loop = None
+    _source_traceback = None
 
     _blocking = False  # proper use of future (yield vs yield from)
 
@@ -155,8 +156,6 @@ class Future:
         self._callbacks = []
         if self._loop.get_debug():
             self._source_traceback = traceback.extract_stack(sys._getframe(1))
-        else:
-            self._source_traceback = None
 
     def _format_callbacks(self):
         cb = self._callbacks
index a2128c5545d2abc720a525b7b07c33b1fc239d01..9aebffdaba3e29f172483a9d9f0531cda3d55f39 100644 (file)
@@ -41,6 +41,10 @@ class Task(futures.Future):
     # all running event loops.  {EventLoop: Task}
     _current_tasks = {}
 
+    # If False, don't log a message if the task is destroyed whereas its
+    # status is still pending
+    _log_destroy_pending = True
+
     @classmethod
     def current_task(cls, loop=None):
         """Return the currently running task in an event loop or None.
@@ -73,9 +77,6 @@ class Task(futures.Future):
         self._must_cancel = False
         self._loop.call_soon(self._step)
         self.__class__._all_tasks.add(self)
-        # If False, don't log a message if the task is destroyed whereas its
-        # status is still pending
-        self._log_destroy_pending = True
 
     # On Python 3.3 or older, objects with a destructor that are part of a
     # reference cycle are never destroyed. That's not the case any more on