Skip to main content

Actor implementation in Python

Project description

# Python Actors README

This library was made so you that you can use Python actors to achieve concurrency in your Python code.

If you are unfamiliar with the actor model, here is a quick rundown * An actor is something capable of accepting a message, and performing work * An actor can be a parent or a child to another actor * Actors accept messages that are posted to them * What an actor does with a message depends on the type of actor

## Generic Actor

A generic actor accepts messages, and can perform work on them. What work is performed is dependent on the developer. Each actor has an on_receive method that must be defined when the actor is defined. An actor’s on_receive should be treated like any other function in Python. An actor will continue to process messages until it is told it is complete, or until it is shut down.

## Countdown Actor

A countdown actor is a special actor that is given a pre-determined number of messages to process before completing when it is defined. Once it has processed that number of messages, it will shut down. * NOTE: countdown actors do work in a do_work method; the on_receive is used by the countdown actor class to accomplish its decrementing job characteristic.

## Split Actor

A split actor is a special actor that accepts an iterable message (list, dictionary, string, generator, etc) and delegates individual messages to a list of child actors (which must be provided when the actor is defined). Delegation is performed round-robin, and the split actor will take care of cleaning up the children actors when it is complete.

## Batch Split Actor

A batch split actor is similar to a split actor, but will send lists of messages to child actors. This allows for batching of a particular job. Batch split actors still accept an iterable message and are defined with a list of children, and optionally a batch size (default is 256).

## Join actor

A join actor accepts messages from multiple parent actors and adds them to a list. When a join actor is defined, a list of parent actors must be provided. When all parent actors have indicated that they are done sending messages, the join actor complete.

## Getting data out of actors

You’ve defined your actor just the way you like it, but you want it to be able to return its results to your inline code…how do you proceed? Well you’ll have to go back to your actor definition, because this is a special use case, but don’t fret, it’s not too bad. First, in your actor definition, redefine __init__ for your actor such that it accepts a new argument, cb. Then tell it to run its parent init (using super().__init__([args])), followed by setting up its self.cb = cb. Basically what you’re doing here is giving your actor a callback, which you can later use to “get your results out”. Now in your actors on_complete method, make the last line of code to execute self.cb.callback(self.results). When you instantiate your class, make sure you give it a CallbackFuture object (the CallbackFuture class can be imported from actors.py), and after you have sent all of your work to the actor (and given it the signal that it is done), tell your code to wait for the actor’s results with results = <callback_object_name>.done()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_actors-0.0.4.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_actors-0.0.4-py2.py3-none-any.whl (5.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file py_actors-0.0.4.tar.gz.

File metadata

  • Download URL: py_actors-0.0.4.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py_actors-0.0.4.tar.gz
Algorithm Hash digest
SHA256 8d6adee1988b7190eff3e3fe773b34305c207ed88e62cd0263c8ac4b876e81bd
MD5 f4d5332e426717f7df5a31fa1ec91eca
BLAKE2b-256 161516567067c6dcc691d63e453ee51462ef51e6bb2f483b1ba37806acfb026e

See more details on using hashes here.

File details

Details for the file py_actors-0.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for py_actors-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6e01c1fc071fa3931c1f5645af11c25f74fe3e35609acaed73f675393efc7bd5
MD5 343fea789e14b6efcdbe3f46ca99c5b4
BLAKE2b-256 6abc661ee758e9d983cbde4c9a0c0009b22ce4c9acb2b190302fad47b830aaea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page