Skip to content

Commit 0a8e44d

Browse files
Merge pull request #33 from HDE/master
Release v0.1.6
2 parents 6b014b7 + fa0e3a8 commit 0a8e44d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lambda_local/timeout.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
'''
55

66
import signal
7+
import threading
78
from contextlib import contextmanager
9+
from six.moves import _thread
810

911

1012
class TimeoutException(Exception):
@@ -13,11 +15,21 @@ class TimeoutException(Exception):
1315

1416
@contextmanager
1517
def time_limit(seconds):
16-
def signal_handler(signum, frame):
17-
raise TimeoutException("Timeout after {} seconds.".format(seconds))
18-
signal.signal(signal.SIGALRM, signal_handler)
19-
signal.alarm(seconds)
20-
try:
21-
yield
22-
finally:
23-
signal.alarm(0)
18+
if hasattr(signal, "SIGALRM"):
19+
def signal_handler(signum, frame):
20+
raise TimeoutException("Timeout after {} seconds.".format(seconds))
21+
signal.signal(signal.SIGALRM, signal_handler)
22+
signal.alarm(seconds)
23+
try:
24+
yield
25+
finally:
26+
signal.alarm(0)
27+
else:
28+
timer = threading.Timer(seconds, lambda: _thread.interrupt_main())
29+
timer.start()
30+
try:
31+
yield
32+
except KeyboardInterrupt:
33+
raise TimeoutException("Timeout after {} seconds.".format(seconds))
34+
finally:
35+
timer.cancel()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def run_tests(self):
2222
sys.exit(pytest.main(self.test_args))
2323

2424

25-
version = "0.1.5"
25+
version = "0.1.6"
2626

2727
setup(name="python-lambda-local",
2828
version=version,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy