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

Method set_running_or_notify_cancel

Lib/concurrent/futures/_base.py:491–529  ·  view source on GitHub ↗

Mark the future as running or process any cancel notifications. Should only be used by Executor implementations and unit tests. If the future has been cancelled (cancel() was called and returned True) then any threads waiting on the future completing (though calls t

(self)

Source from the content-addressed store, hash-verified

489
490 # The following methods should only be used by Executors and in tests.
491 def set_running_or_notify_cancel(self):
492 """Mark the future as running or process any cancel notifications.
493
494 Should only be used by Executor implementations and unit tests.
495
496 If the future has been cancelled (cancel() was called and returned
497 True) then any threads waiting on the future completing (though calls
498 to as_completed() or wait()) are notified and False is returned.
499
500 If the future was not cancelled then it is put in the running state
501 (future calls to running() will return True) and True is returned.
502
503 This method should be called by Executor implementations before
504 executing the work associated with this future. If this method returns
505 False then the work should not be executed.
506
507 Returns:
508 False if the Future was cancelled, True otherwise.
509
510 Raises:
511 RuntimeError: if this method was already called or if set_result()
512 or set_exception() was called.
513 """
514 with self._condition:
515 if self._state == CANCELLED:
516 self._state = CANCELLED_AND_NOTIFIED
517 for waiter in self._waiters:
518 waiter.add_cancelled(self)
519 # self._condition.notify_all() is not necessary because
520 # self.cancel() triggers a notification.
521 return False
522 elif self._state == PENDING:
523 self._state = RUNNING
524 return True
525 else:
526 LOGGER.critical('Future %s in unexpected state: %s',
527 id(self),
528 self._state)
529 raise RuntimeError('Future in unexpected state')
530
531 def set_result(self, result):
532 """Sets the return value of work associated with the future.

Callers 4

callbackFunction · 0.80
runMethod · 0.80

Calls 3

idFunction · 0.85
add_cancelledMethod · 0.45
criticalMethod · 0.45

Tested by

no test coverage detected