# Threading

## Installation

The default threading runtime has no dependencies other than Pykka itself and the Python standard library.

## API

class `pykka.``ThreadingFuture`

  `ThreadingFuture` implements `Future` for use with `ThreadingActor`.

  The future is implemented using a `queue.Queue`.

  The future does not make a copy of the object which is `set()` on it. It is the setters responsibility to only pass immutable objects or make a copy of the object before setting it on the future.

  Changed in version 0.14: Previously, the encapsulated value was a copy made with `copy.deepcopy()`, unless the encapsulated value was a future, in which case the original future was encapsulated.

  `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.``ThreadingActor`(*args, **kwargs)

  `ThreadingActor` implements `Actor` using regular Python threads.

  This implementation is slower than `GeventActor`, but can be used in a process with other threads that are not Pykka actors.

  `use_daemon_thread` = False

    A boolean value indicating whether this actor is executed on a thread that is a daemon thread (`True`) or not (`False`). This must be set before `pykka.Actor.start()` is called, otherwise `RuntimeError` is raised.

    The entire Python program exits when no alive non-daemon threads are left. This means that an actor running on a daemon thread may be interrupted at any time, and there is no guarantee that cleanup will be done or that `pykka.Actor.on_stop()` will be called.

    Actors do not inherit the daemon flag from the actor that made it. It always has to be set explicitly for the actor to run on a daemonic thread.