Signal the interrupt and (from a worker thread) wake the main thread. On the main thread: re-raises with ``from ki`` so the exception chain is preserved in tracebacks. On a worker thread: sets the global interrupt flag and wakes the main thread.
(ki: KeyboardInterrupt)
| 177 | |
| 178 | |
| 179 | def handle_keyboard_interrupt(ki: KeyboardInterrupt) -> None: |
| 180 | """Signal the interrupt and (from a worker thread) wake the main thread. |
| 181 | |
| 182 | On the main thread: re-raises with ``from ki`` so the exception chain |
| 183 | is preserved in tracebacks. |
| 184 | On a worker thread: sets the global interrupt flag and wakes the main thread. |
| 185 | """ |
| 186 | _print_caller("handle_keyboard_interrupt") |
| 187 | if threading.current_thread() is threading.main_thread(): |
| 188 | raise KeyboardInterrupt() |
| 189 | notify_main_thread() |
| 190 | |
| 191 | |
| 192 | def wait_for_cleanup() -> None: |