I do not have any docs named signal.py
Code:
Code:
import signal class TimeOut: def __init__(self, timeout): self.timeout = timeout self._orig_handler = signal.signal(signal.SIGALRM, self._timeout) def __enter__(self): signal.alarm(self.timeout) return self def __exit__(self, *args): signal.signal(signal.SIGALRM, self._orig_handler) def _timeout(self, *args): raise TimeoutError with TimeOut(5): try: input('Answer in 5 seconds: ') except TimeoutError: print('\nTime is up!')