Skip to content

Commit

Permalink
Move timeout cancelation into context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kolanos committed Jun 6, 2019
1 parent 043cc66 commit 0f74d6c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions iopipe/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ def wrapped(event, context):
try:
with Timeout(timeout_duration, False) as timeout:
result = func(event, context)
timeout.cancel()
except Exception as e:

self.run_hooks("post:invoke", event=event, context=context)

frame = None
if isinstance(e, TimeoutError):
logger.debug(
"Function about to timeout; reporting current stack frame"
)
frame = inspect.currentframe()

# This prevents this block from being executed a second time in the
Expand All @@ -168,7 +171,6 @@ def wrapped(event, context):
self.report.send()
self.run_hooks("post:report")
finally:
timeout.cancel()
self.wait_for_futures()

return result
Expand Down

0 comments on commit 0f74d6c

Please sign in to comment.