mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
asyncio: Initialize more Future and Task attributes in the class definition to
avoid attribute errors in destructors.
This commit is contained in:
parent
bb37b4ca73
commit
fe22e0985a
2 changed files with 5 additions and 5 deletions
|
@ -135,6 +135,7 @@ class Future:
|
||||||
_result = None
|
_result = None
|
||||||
_exception = None
|
_exception = None
|
||||||
_loop = None
|
_loop = None
|
||||||
|
_source_traceback = None
|
||||||
|
|
||||||
_blocking = False # proper use of future (yield vs yield from)
|
_blocking = False # proper use of future (yield vs yield from)
|
||||||
|
|
||||||
|
@ -155,8 +156,6 @@ class Future:
|
||||||
self._callbacks = []
|
self._callbacks = []
|
||||||
if self._loop.get_debug():
|
if self._loop.get_debug():
|
||||||
self._source_traceback = traceback.extract_stack(sys._getframe(1))
|
self._source_traceback = traceback.extract_stack(sys._getframe(1))
|
||||||
else:
|
|
||||||
self._source_traceback = None
|
|
||||||
|
|
||||||
def _format_callbacks(self):
|
def _format_callbacks(self):
|
||||||
cb = self._callbacks
|
cb = self._callbacks
|
||||||
|
|
|
@ -41,6 +41,10 @@ class Task(futures.Future):
|
||||||
# all running event loops. {EventLoop: Task}
|
# all running event loops. {EventLoop: Task}
|
||||||
_current_tasks = {}
|
_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
|
@classmethod
|
||||||
def current_task(cls, loop=None):
|
def current_task(cls, loop=None):
|
||||||
"""Return the currently running task in an event loop or 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._must_cancel = False
|
||||||
self._loop.call_soon(self._step)
|
self._loop.call_soon(self._step)
|
||||||
self.__class__._all_tasks.add(self)
|
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
|
# 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
|
# reference cycle are never destroyed. That's not the case any more on
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue