Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make swallow_exc a paramater with default value #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
@@ -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:
@@ -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)