(seconds: float)
| 89 | |
| 90 | @contextlib.contextmanager |
| 91 | def time_limit(seconds: float): |
| 92 | def signal_handler(signum, frame): |
| 93 | raise TimeoutException("Timed out!") |
| 94 | signal.setitimer(signal.ITIMER_REAL, seconds) |
| 95 | signal.signal(signal.SIGALRM, signal_handler) |
| 96 | try: |
| 97 | yield |
| 98 | finally: |
| 99 | signal.setitimer(signal.ITIMER_REAL, 0) |
| 100 | |
| 101 | |
| 102 | @contextlib.contextmanager |