Created
August 1, 2022 10:06
-
-
Save shar1z/24b65853c13cb6b92fc97e04173b652e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@contextlib.contextmanager | |
def time_limit(seconds): | |
def raise_timeout(signum, frame): | |
raise TimeoutError('Timed out!') | |
signal.signal(signal.SIGALRM, raise_timeout) | |
signal.alarm(seconds) | |
yield | |
signal.alarm(0) # Disable the alarm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment