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)
| 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. |