Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/stopit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if self.state != BaseTimeout.TIMED_OUT:
self.state = BaseTimeout.INTERRUPTED
self.suppress_interrupt()
LOG.warning("Code block execution exceeded {0} seconds timeout".format(self.seconds),
boolean = " not" if self.swallow_exc else ""
LOG.warning("Code block execution exceeded {0} seconds timeout and this exception will{1} be raised to client code".format(self.seconds,boolean),
exc_info=(exc_type, exc_val, exc_tb))
return self.swallow_exc
else:
Expand Down Expand Up @@ -131,15 +132,15 @@ class base_timeoutable(object): # noqa
"""
to_ctx_mgr = None

def __init__(self, default=None, timeout_param='timeout'):
self.default, self.timeout_param = default, timeout_param
def __init__(self, default=None, timeout_param='timeout', swallow_exc=True):
self.default, self.timeout_param, self.swallow_exc = default, timeout_param, swallow_exc

def __call__(self, func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
timeout = kwargs.pop(self.timeout_param, None)
if timeout:
with self.to_ctx_mgr(timeout, swallow_exc=True):
with self.to_ctx_mgr(timeout, swallow_exc=self.swallow_exc):
result = self.default # noqa
# ``result`` may not be assigned below in case of timeout
result = func(*args, **kwargs)
Expand Down