@@ -385,7 +385,11 @@ def done(self):
385
385
386
386
def __get_result (self ):
387
387
if self ._exception :
388
- raise self ._exception
388
+ try :
389
+ raise self ._exception
390
+ finally :
391
+ # Break a reference cycle with the exception in self._exception
392
+ self = None
389
393
else :
390
394
return self ._result
391
395
@@ -425,20 +429,24 @@ def result(self, timeout=None):
425
429
timeout.
426
430
Exception: If the call raised then that exception will be raised.
427
431
"""
428
- with self ._condition :
429
- if self ._state in [CANCELLED , CANCELLED_AND_NOTIFIED ]:
430
- raise CancelledError ()
431
- elif self ._state == FINISHED :
432
- return self .__get_result ()
433
-
434
- self ._condition .wait (timeout )
435
-
436
- if self ._state in [CANCELLED , CANCELLED_AND_NOTIFIED ]:
437
- raise CancelledError ()
438
- elif self ._state == FINISHED :
439
- return self .__get_result ()
440
- else :
441
- raise TimeoutError ()
432
+ try :
433
+ with self ._condition :
434
+ if self ._state in [CANCELLED , CANCELLED_AND_NOTIFIED ]:
435
+ raise CancelledError ()
436
+ elif self ._state == FINISHED :
437
+ return self .__get_result ()
438
+
439
+ self ._condition .wait (timeout )
440
+
441
+ if self ._state in [CANCELLED , CANCELLED_AND_NOTIFIED ]:
442
+ raise CancelledError ()
443
+ elif self ._state == FINISHED :
444
+ return self .__get_result ()
445
+ else :
446
+ raise TimeoutError ()
447
+ finally :
448
+ # Break a reference cycle with the exception in self._exception
449
+ self = None
442
450
443
451
def exception (self , timeout = None ):
444
452
"""Return the exception raised by the call that the future represents.
0 commit comments