Commit 950eea41 authored by Denis Bilenko's avatar Denis Bilenko

add a few docstrings to Timeout's methods

parent d327559d
...@@ -88,6 +88,7 @@ class Timeout(BaseException): ...@@ -88,6 +88,7 @@ class Timeout(BaseException):
self.timer = None self.timer = None
def start(self): def start(self):
"""Schedule the timeout."""
assert not self.pending, '%r is already started; to restart it, cancel it first' % self assert not self.pending, '%r is already started; to restart it, cancel it first' % self
if self.seconds is None: # "fake" timeout (never expires) if self.seconds is None: # "fake" timeout (never expires)
self.timer = None self.timer = None
...@@ -98,6 +99,16 @@ class Timeout(BaseException): ...@@ -98,6 +99,16 @@ class Timeout(BaseException):
@classmethod @classmethod
def start_new(cls, timeout=None, exception=None): def start_new(cls, timeout=None, exception=None):
"""Create a started :class:`Timeout`.
This is a shortcut, the exact action depends on *timeout*'s type:
* If *timeout* is a :class:`Timeout`, then call its :meth:`start` method.
* Otherwise, create a new :class:`Timeout` instance, passing (*timeout*, *exception*) as
arguments, then call its :meth:`start` method.
Returns the :class:`Timeout` instance.
"""
if isinstance(timeout, Timeout): if isinstance(timeout, Timeout):
if not timeout.pending: if not timeout.pending:
timeout.start() timeout.start()
...@@ -108,12 +119,14 @@ class Timeout(BaseException): ...@@ -108,12 +119,14 @@ class Timeout(BaseException):
@property @property
def pending(self): def pending(self):
"""Return True if the timeout is pending, that is, scheduled to be raised."""
if self.timer is not None: if self.timer is not None:
return self.timer.pending return self.timer.pending
else: else:
return False return False
def cancel(self): def cancel(self):
"""If the timeout is pending, cancel it. Otherwise, do nothing."""
if self.timer is not None: if self.timer is not None:
self.timer.cancel() self.timer.cancel()
......
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