Download make_variations_basic/utils.py from Fraser/python-state-changes: direct link, hf CLI and curl.
- Browser
- Download file 628 Bytes
-
https://huggingface.co/datasets/Fraser/python-state-changes/resolve/c6f8ae3b72dc6ef37f20c6b26ce0c85134247715/make_variations_basic/utils.py
- Command line
-
hf download hf://datasets/Fraser/python-state-changes@c6f8ae3b72dc6ef37f20c6b26ce0c85134247715/make_variations_basic/utils.py
-
curl -L -o utils.py https://huggingface.co/datasets/Fraser/python-state-changes/resolve/c6f8ae3b72dc6ef37f20c6b26ce0c85134247715/make_variations_basic/utils.py
628 Bytes
| import errno | |
| import os | |
| import signal | |
| import functools | |
| class TimeoutError(Exception): | |
| pass | |
| def timeout(seconds=10, error_message=os.strerror(errno.ETIME)): | |
| def decorator(func): | |
| def _handle_timeout(signum, frame): | |
| raise TimeoutError(error_message) | |
| def wrapper(*args, **kwargs): | |
| signal.signal(signal.SIGALRM, _handle_timeout) | |
| signal.alarm(seconds) | |
| try: | |
| result = func(*args, **kwargs) | |
| finally: | |
| signal.alarm(0) | |
| return result | |
| return wrapper | |
| return decorator | |