osc.utils.SigIntCatcher

class SigIntCatcher[source]

Bases: contextlib.AbstractContextManager

Context manager to gracefully handle SIGINT or KeyboardInterrupt.

Example

Gracefully terminate a loop:

>>> with SigIntCatcher() as should_stop:
>>>     for i in range(1000):
>>>         print(f"Step {i}...")
>>>         time.sleep(5)
>>>         print("Done")
>>>         if should_stop:
>>>             break

Methods