# gevent

## Installation

To run Pykka on top of gevent, you first need to install the gevent package from PyPI:

    pip install gevent

## Code changes

Next, all actors must subclass `pykka.gevent.GeventActor` instead of `pykka.ThreadingActor`.

If you create any futures yourself, you must replace `pykka.ThreadingFuture` with `pykka.gevent.GeventFuture`.

With those changes in place, Pykka should run on top of gevent.

## API

class `pykka.gevent.``GeventFuture`(async_result=None)

  `GeventFuture` implements `pykka.Future` for use with `GeventActor`.

  It encapsulates a `gevent.event.AsyncResult` object which may be used directly, though it will couple your code with gevent.

  `async_result` = None

    The encapsulated `gevent.event.AsyncResult`

  `get`(timeout=None)

    Get the value encapsulated by the future.

    If the encapsulated value is an exception, it is raised instead of returned.

    If `timeout` is `None`, as default, the method will block until it gets a reply, potentially forever. If `timeout` is an integer or float, the method will wait for a reply for `timeout` seconds, and then raise `pykka.Timeout`.

    The encapsulated value can be retrieved multiple times. The future will only block the first time the value is accessed.

    Parameters: | timeout (float or `None`) – seconds to wait before timeout
    Raise: | `pykka.Timeout` if timeout is reached
    Raise: | encapsulated value if it is an exception
    Returns: | encapsulated value if it is not an exception

  `set`(value=None)

    Set the encapsulated value.

    Parameters: | value (any object or `None`) – the encapsulated value or nothing
    Raise: | an exception if set is called multiple times

  `set_exception`(exc_info=None)

    Set an exception as the encapsulated value.

    You can pass an `exc_info` three-tuple, as returned by `sys.exc_info()`. If you don’t pass `exc_info`, `sys.exc_info()` will be called and the value returned by it used.

    In other words, if you’re calling `set_exception()`, without any arguments, from an except block, the exception you’re currently handling will automatically be set on the future.

    Parameters: | exc_info (three-tuple of (exc_class, exc_instance, traceback)) – the encapsulated exception

class `pykka.gevent.``GeventActor`(*args, **kwargs)

  `GeventActor` implements `pykka.Actor` using the gevent library. gevent is a coroutine-based Python networking library that uses greenlet to provide a high-level synchronous API on top of libevent event loop.

  This is a very fast implementation.