Closed deeplook closed 9 years ago
A suggestion to make this Python 3 compliant, note the test for PY_VERSION:
import sys PY_VERSION = sys.version_info[0] # ... def timeout(seconds_before_timeout): def decorate(f): def handler(signum, frame): raise TimeoutError() def new_f(*args, **kwargs): old = signal.signal(signal.SIGALRM, handler) signal.alarm(seconds_before_timeout) try: result = f(*args, **kwargs) finally: signal.signal(signal.SIGALRM, old) signal.alarm(0) return result if PY_VERSION == 2: new_f.func_name = f.func_name elif PY_VERSION == 3: new_f.func_name = f.__name__ return new_f return decorate
Can you make a pull request? Thanks!
Sorry, too busy...
This issue was resolved by #5
A suggestion to make this Python 3 compliant, note the test for PY_VERSION: