Threading
Installation
The default threading runtime has no dependencies other than Pykka itself and the Python standard library.
API
- class pykka.ThreadingFuture[source]
ThreadingFuture
implementsFuture
for use withThreadingActor
.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)[source]
Get the value encapsulated by the future.
If the encapsulated value is an exception, it is raised instead of returned.
If
timeout
isNone
, as default, the method will block until it gets a reply, potentially forever. Iftimeout
is an integer or float, the method will wait for a reply fortimeout
seconds, and then raisepykka.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)[source]
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)[source]
Set an exception as the encapsulated value.
You can pass an
exc_info
three-tuple, as returned bysys.exc_info()
. If you don’t passexc_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)[source]
ThreadingActor
implementsActor
using regular Python threads.- 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 beforepykka.Actor.start()
is called, otherwiseRuntimeError
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.