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
(self, n=1)
| 364 | return result |
| 365 | |
| 366 | def notify(self, n=1): |
| 367 | """Wake up one or more threads waiting on this condition, if any. |
| 368 | |
| 369 | If the calling thread has not acquired the lock when this method is |
| 370 | called, a RuntimeError is raised. |
| 371 | |
| 372 | This method wakes up at most n of the threads waiting for the condition |
| 373 | variable; it is a no-op if no threads are waiting. |
| 374 | |
| 375 | """ |
| 376 | if not self._is_owned(): |
| 377 | raise RuntimeError("cannot notify on un-acquired lock") |
| 378 | waiters = self._waiters |
| 379 | while waiters and n > 0: |
| 380 | waiter = waiters[0] |
| 381 | try: |
| 382 | waiter.release() |
| 383 | except RuntimeError: |
| 384 | # gh-92530: The previous call of notify() released the lock, |
| 385 | # but was interrupted before removing it from the queue. |
| 386 | # It can happen if a signal handler raises an exception, |
| 387 | # like CTRL+C which raises KeyboardInterrupt. |
| 388 | pass |
| 389 | else: |
| 390 | n -= 1 |
| 391 | try: |
| 392 | waiters.remove(waiter) |
| 393 | except ValueError: |
| 394 | pass |
| 395 | |
| 396 | def notify_all(self): |
| 397 | """Wake up all threads waiting on this condition. |