data_base
❭ utils
❭ DelayedKeyboardInterrupt
DelayedKeyboardInterrupt¶
- class data_base.utils.DelayedKeyboardInterrupt¶
Context manager that allows to delay a KeyboardInterrupt such that it also works in subthreads.
If a KeyboardInterrupt is received while code is still running within this context manager, the KeyboardInterrupt is intercepted by this class and delayed until the context manager is exited.
The usecase is to allow for subthreads to finish their work before the KeyboardInterrupt is raised.
Example
>>> with DelayedKeyboardInterrupt(): ... time.sleep(10) # press Ctrl+C here, after <10s ... print("I am finished after 10 seconds") I am finished after 10 seconds
- Methods:¶
handler
(sig, frame)Handle KeyboardInterrupt signals and delay them