Commit 571954cc authored by Denis Bilenko's avatar Denis Bilenko

gevent.hub: rst markup docstrings

parent 846394bf
...@@ -56,15 +56,11 @@ def spawn_raw(function, *args, **kwargs): ...@@ -56,15 +56,11 @@ def spawn_raw(function, *args, **kwargs):
def sleep(seconds=0): def sleep(seconds=0):
"""Yield control to another eligible coroutine until at least *seconds* have """Put the current greenlet to sleep for at least *seconds*.
elapsed.
*seconds* may be specified as an integer, or a float if fractional seconds *seconds* may be specified as an integer, or a float if fractional seconds
are desired. Calling sleep with *seconds* of 0 is the canonical way of are desired. Calling sleep with *seconds* of 0 is the canonical way of
expressing a cooperative yield. For example, if one is looping over a expressing a cooperative yield.
large list performing an expensive calculation without calling any socket
methods, it's a good idea to call ``sleep(0)`` occasionally; otherwise
nothing else will run.
""" """
unique_mark = object() unique_mark = object()
t = core.timer(seconds, getcurrent().switch, unique_mark) t = core.timer(seconds, getcurrent().switch, unique_mark)
...@@ -79,8 +75,9 @@ def sleep(seconds=0): ...@@ -79,8 +75,9 @@ def sleep(seconds=0):
def kill(greenlet, exception=GreenletExit): def kill(greenlet, exception=GreenletExit):
"""Kill greenlet asynchronously. The current greenlet is not unscheduled. """Kill greenlet asynchronously. The current greenlet is not unscheduled.
Note, that Greenlet's kill() method does the same and more. However, MAIN Note, that :meth:`gevent.Greenlet.kill` method does the same and more. However,
greenlet does not have kill() method so you have to use this function. MAIN greenlet - the one that exists initially - does not have ``kill()`` method
so you have to use this function.
""" """
if not greenlet.dead: if not greenlet.dead:
core.active_event(greenlet.throw, exception) core.active_event(greenlet.throw, exception)
...@@ -130,6 +127,10 @@ def get_hub(): ...@@ -130,6 +127,10 @@ def get_hub():
class Hub(greenlet): class Hub(greenlet):
"""A greenlet that runs the event loop.
It is created automatically by :func:`get_hub`.
"""
def __init__(self): def __init__(self):
self.keyboard_interrupt_signal = None self.keyboard_interrupt_signal = None
...@@ -192,13 +193,14 @@ class DispatchExit(Exception): ...@@ -192,13 +193,14 @@ class DispatchExit(Exception):
class Waiter(object): class Waiter(object):
"""A low level synchronization class. """A low level synchronization class.
Wrapper around switch() and throw() calls that makes them safe: Wrapper around greenlet's ``switch()`` and ``throw()`` calls that makes them safe:
a) switching will occur only if the waiting greenlet is executing wait()
method currently. Otherwise, switch() and throw() are no-ops.
b) any error raised in the greenlet is handled inside switch() and throw()
switch and throw methods must only be called from the mainloop greenlet. * switching will occur only if the waiting greenlet is executing :meth:`wait`
wait must be called from a greenlet other than mainloop. method currently. Otherwise, :meth:`switch` and :meth:`throw` are no-ops.
* any error raised in the greenlet is handled inside :meth:`switch` and :meth:`throw`
The :meth:`switch` and :meth:`throw` methods must only be called from the :class:`Hub` greenlet.
The :meth:`wait` method must be called from a greenlet other than :class:`Hub`.
""" """
__slots__ = ['greenlet'] __slots__ = ['greenlet']
...@@ -252,7 +254,7 @@ class Waiter(object): ...@@ -252,7 +254,7 @@ class Waiter(object):
except: except:
traceback.print_exc() traceback.print_exc()
# QQQ should be renamed to get() ? and the whole class is called Receiver? # XXX should be renamed to get() ? and the whole class is called Receiver?
def wait(self): def wait(self):
"""Wait until switch() or throw() is called. """Wait until switch() or throw() is called.
""" """
...@@ -263,3 +265,6 @@ class Waiter(object): ...@@ -263,3 +265,6 @@ class Waiter(object):
finally: finally:
self.greenlet = None self.greenlet = None
# can also have a debugging version, that wraps the value in a tuple (self, value) in switch()
# and unwraps it in wait() thus checking that switch() was indeed called
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