Commit 85663044 authored by Denis Bilenko's avatar Denis Bilenko

get rid of _SilentException

parent 772ff231
......@@ -171,13 +171,6 @@ except NameError: # Python < 2.5
pass
class _SilentException(BaseException):
"""Used internally by Timeout as an exception which is not raised outside of with-block,
and therefore is not visible by the user, unless she uses "except:" construct.
"""
__slots__ = []
class Timeout(BaseException):
"""Raise an exception in the current greenlet after timeout.
......@@ -199,10 +192,8 @@ class Timeout(BaseException):
... code block ...
This is equivalent to try/finally block above with one additional feature:
if exception is False, code block will be interrupted "silently". Under the
hood, an exception of a type _SilentException (subclass of BaseException
but not Exception) is raised. If it exits the block it is suppressed by the
context manager, so that outside code won't see it.
if exception is False, the timeout is still raised, but context manager
suppresses it, so surrounding code won't see it.
This is handy for adding a timeout feature to the functions that don't
implement it themselves:
......@@ -234,12 +225,9 @@ class Timeout(BaseException):
if seconds is None: # "fake" timeout (never expires)
self.exception = None
self.timer = None
elif exception is None: # timeout that raises self
self.exception = None
elif exception is None or exception is False: # timeout that raises self
self.exception = exception
self.timer = core.timer(seconds, getcurrent().throw, self)
elif exception is False: # timeout that interrupts the with-block "silently"
self.exception = _SilentException()
self.timer = core.timer(seconds, getcurrent().throw, self.exception)
else: # regular timeout with user-provided exception
self.exception = exception
self.timer = core.timer(seconds, getcurrent().throw, exception)
......@@ -282,7 +270,7 @@ class Timeout(BaseException):
def __exit__(self, typ, value, tb):
self.cancel()
if typ is _SilentException and value is self.exception:
if value is self and self.exception is False:
return True
......
......@@ -25,7 +25,6 @@ import greentest
import weakref
import time
from gevent import sleep, Timeout
from gevent.greenlet import _SilentException
DELAY = 0.04
class Error(Exception):
......@@ -84,9 +83,7 @@ class Test(greentest.TestCase):
timer.cancel()
sleep(DELAY*2)
# To silent the exception, pass False as second parameter. The with-block
# will be interrupted with _SilentException, but it won't be propagated
# outside.
# To silent the exception before exiting the block, pass False as second parameter.
XDELAY=0.1
start = time.time()
with Timeout(XDELAY, False):
......@@ -113,11 +110,6 @@ class Test(greentest.TestCase):
sleep(DELAY*3)
raise AssertionError('should not get there')
with Timeout(DELAY, _SilentException()):
with Timeout(DELAY*2, _SilentException()):
sleep(DELAY*3)
raise AssertionError('should not get there')
with Timeout(DELAY) as t1:
with Timeout(DELAY*2) as t2:
try:
......
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