Skip to content

Commit

Permalink
switch to using signal.setitimer so we can restore previous timer
Browse files Browse the repository at this point in the history
  • Loading branch information
jesopo committed Aug 30, 2019
1 parent a57a06b commit 722d641
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,15 @@ def _raise_deadline():
def deadline(seconds: int=10):
old_handler = signal.signal(signal.SIGALRM,
lambda _1, _2: _raise_deadline())
signal.alarm(seconds)
old_seconds, _ = signal.setitimer(signal.ITIMER_REAL, seconds, 0)

if not old_seconds == 0.0 and seconds > old_seconds:
raise ValueError(
"Deadline timeout larger than parent deadline (%s > %s)" %
(seconds, old_seconds))

try:
yield
finally:
signal.signal(signal.SIGALRM, old_handler)
signal.setitimer(signal.ITIMER_REAL, old_seconds, 0)

0 comments on commit 722d641

Please sign in to comment.