MCPcopy Index your code
hub / github.com/python/cpython / _get_snapshot

Method _get_snapshot

Lib/concurrent/futures/_base.py:561–586  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

test_get_snapshotMethod · 0.95
_copy_future_stateFunction · 0.80
get_snapshotMethod · 0.80

Calls

no outgoing calls

Tested by 2

test_get_snapshotMethod · 0.76
get_snapshotMethod · 0.64