Skip to content

Commit 32430aa

Browse files
authored
1 parent 7bfd65e commit 32430aa

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

Lib/concurrent/futures/_base.py

+23-15
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,11 @@ def done(self):
386386

387387
def __get_result(self):
388388
if self._exception:
389-
raise self._exception
389+
try:
390+
raise self._exception
391+
finally:
392+
# Break a reference cycle with the exception in self._exception
393+
self = None
390394
else:
391395
return self._result
392396

@@ -426,20 +430,24 @@ def result(self, timeout=None):
426430
timeout.
427431
Exception: If the call raised then that exception will be raised.
428432
"""
429-
with self._condition:
430-
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
431-
raise CancelledError()
432-
elif self._state == FINISHED:
433-
return self.__get_result()
434-
435-
self._condition.wait(timeout)
436-
437-
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
438-
raise CancelledError()
439-
elif self._state == FINISHED:
440-
return self.__get_result()
441-
else:
442-
raise TimeoutError()
433+
try:
434+
with self._condition:
435+
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
436+
raise CancelledError()
437+
elif self._state == FINISHED:
438+
return self.__get_result()
439+
440+
self._condition.wait(timeout)
441+
442+
if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
443+
raise CancelledError()
444+
elif self._state == FINISHED:
445+
return self.__get_result()
446+
else:
447+
raise TimeoutError()
448+
finally:
449+
# Break a reference cycle with the exception in self._exception
450+
self = None
443451

444452
def exception(self, timeout=None):
445453
"""Return the exception raised by the call that the future represents.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raising an exception raised in a "future" instance will create reference
2+
cycles.

0 commit comments

Comments
 (0)