@@ -386,7 +386,11 @@ def done(self):
386
386
387
387
def __get_result (self ):
388
388
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
390
394
else :
391
395
return self ._result
392
396
@@ -426,20 +430,24 @@ def result(self, timeout=None):
426
430
timeout.
427
431
Exception: If the call raised then that exception will be raised.
428
432
"""
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
443
451
444
452
def exception (self , timeout = None ):
445
453
"""Return the exception raised by the call that the future represents.
0 commit comments