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

Method notify

Lib/threading.py:401–429  ·  view source on GitHub ↗

Wake up one or more threads waiting on this condition, if any. If the calling thread has not acquired the lock when this method is called, a RuntimeError is raised. This method wakes up at most n of the threads waiting for the condition variable; it is a no-op if no

(self, n=1)

Source from the content-addressed store, hash-verified

399 return result
400
401 def notify(self, n=1):
402 """Wake up one or more threads waiting on this condition, if any.
403
404 If the calling thread has not acquired the lock when this method is
405 called, a RuntimeError is raised.
406
407 This method wakes up at most n of the threads waiting for the condition
408 variable; it is a no-op if no threads are waiting.
409
410 """
411 if not self._is_owned():
412 raise RuntimeError("cannot notify on un-acquired lock")
413 waiters = self._waiters
414 while waiters and n > 0:
415 waiter = waiters[0]
416 try:
417 waiter.release()
418 except RuntimeError:
419 # gh-92530: The previous call of notify() released the lock,
420 # but was interrupted before removing it from the queue.
421 # It can happen if a signal handler raises an exception,
422 # like CTRL+C which raises KeyboardInterrupt.
423 pass
424 else:
425 n -= 1
426 try:
427 waiters.remove(waiter)
428 except ValueError:
429 pass
430
431 def notify_all(self):
432 """Wake up all threads waiting on this condition.

Callers 5

notify_allMethod · 0.95
releaseMethod · 0.45
releaseMethod · 0.45
putMethod · 0.45
getMethod · 0.45

Calls 3

_is_ownedMethod · 0.95
releaseMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected