Commit e6c31129 authored by Denis Bilenko's avatar Denis Bilenko

timeout: improve readability

parent afa84cba
...@@ -154,16 +154,16 @@ class Timeout(BaseException): ...@@ -154,16 +154,16 @@ class Timeout(BaseException):
""" """
if self.seconds is None: if self.seconds is None:
return '' return ''
if self.seconds==1: if self.seconds == 1:
s = '' suffix = ''
else: else:
s = 's' suffix = 's'
if self.exception is None: if self.exception is None:
return '%s second%s' % (self.seconds, s) return '%s second%s' % (self.seconds, suffix)
elif self.exception is False: elif self.exception is False:
return '%s second%s (silent)' % (self.seconds, s) return '%s second%s (silent)' % (self.seconds, suffix)
else: else:
return '%s second%s (%s)' % (self.seconds, s, self.exception) return '%s second%s (%s)' % (self.seconds, suffix, self.exception)
def __enter__(self): def __enter__(self):
if self.timer is None: if self.timer is None:
...@@ -190,8 +190,8 @@ def with_timeout(seconds, function, *args, **kwds): ...@@ -190,8 +190,8 @@ def with_timeout(seconds, function, *args, **kwds):
try: try:
try: try:
return function(*args, **kwds) return function(*args, **kwds)
except Timeout, t: except Timeout, ex:
if t is timeout and timeout_value is not _NONE: if ex is timeout and timeout_value is not _NONE:
return timeout_value return timeout_value
raise raise
finally: finally:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment