8000 asyncio: Initialize more Future and Task attributes in the class defi… · python/cpython@fe22e09 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe22e09

Browse files
committed
asyncio: Initialize more Future and Task attributes in the class definition to
avoid attribute errors in destructors.
1 parent bb37b4c commit fe22e09

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Lib/asyncio/futures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class Future:
135135
_result = None
136136
_exception = None
137137
_loop = None
138+
_source_traceback = None
138139

139140
_blocking = False # proper use of future (yield vs yield from)
140141

@@ -155,8 +156,6 @@ def __init__(self, *, loop=None):
155156
self._callbacks = []
156157
if self._loop.get_debug():
157158
self._source_traceback = traceback.extract_stack(sys._getframe(1))
158-
else:
159-
self._source_traceback = None
160159

161160
def _format_callbacks(self):
162161
cb = self._callbacks

Lib/asyncio/tasks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class Task(futures.Future):
4141
# all running event loops. {EventLoop: Task}
4242
_current_tasks = {}
4343

44+
# If False, don't log a message if the task is destroyed whereas its
45+
# status is still pending
46+
_log_destroy_pending = True
47+
4448
@classmethod
4549
def current_task(cls, loop=None):
4650
"""Return the currently running task in an event loop or None.
@@ -73,9 +77,6 @@ def __init__(self, coro, *, loop=None):
7377
self._must_cancel = False
7478
self._loop.call_soon(self._step)
7579
self.__class__._all_tasks.add(self)
76-
# If False, don't log a message if the task is destroyed whereas its
77-
# status is still pending
78-
self._log_destroy_pending = True
7980

8081
# On Python 3.3 or older, objects with a destructor that are part of a
8182
# reference cycle are never destroyed. That's not the case any more on

0 commit comments

Comments
 (0)
0