Get a snapshot of the future's current state. This method atomically retrieves the state in one lock acquisition, which is significantly faster than multiple method calls. Returns: Tuple of (done, cancelled, result, exception) - done: True if the fut
(self)
| 559 | self._invoke_callbacks() |
| 560 | |
| 561 | def _get_snapshot(self): |
| 562 | """Get a snapshot of the future's current state. |
| 563 | |
| 564 | This method atomically retrieves the state in one lock acquisition, |
| 565 | which is significantly faster than multiple method calls. |
| 566 | |
| 567 | Returns: |
| 568 | Tuple of (done, cancelled, result, exception) |
| 569 | - done: True if the future is done (cancelled or finished) |
| 570 | - cancelled: True if the future was cancelled |
| 571 | - result: The result if available and not cancelled |
| 572 | - exception: The exception if available and not cancelled |
| 573 | """ |
| 574 | # Fast path: check if already finished without lock |
| 575 | if self._state == FINISHED: |
| 576 | return True, False, self._result, self._exception |
| 577 | |
| 578 | # Need lock for other states since they can change |
| 579 | with self._condition: |
| 580 | # We have to check the state again after acquiring the lock |
| 581 | # because it may have changed in the meantime. |
| 582 | if self._state == FINISHED: |
| 583 | return True, False, self._result, self._exception |
| 584 | if self._state in {CANCELLED, CANCELLED_AND_NOTIFIED}: |
| 585 | return True, True, None, None |
| 586 | return False, False, None, None |
| 587 | |
| 588 | __class_getitem__ = classmethod(types.GenericAlias) |
| 589 |
no outgoing calls