46

I am looking for an easy-to-learn Actor library or framework for Python 2.x. I have tried Candygram and Twisted but I did not like them. I'd like something that will be easy to extend to suppero Greenlet (= stackless python).

  • Candygram is too old.
  • Twisted is too complicated.
  • Gevent: it is unclear if it can support Actors model.

What do you suggest?

tshepang
  • 12,111
  • 21
  • 91
  • 136
daitangio
  • 583
  • 1
  • 6
  • 18
  • 4
    I don't know anything about Candygram, but I thought Twisted was more oriented around networking than around Actor-based concurrency. – Daniel Yankowsky Aug 06 '10 at 12:43
  • 1
    The best Erlang like actors are implemented in Erlang. Do concurrent oriented work in Erlang and left rest of work to python through ports. I would do whole work in Erlang but if someone think that Python is better for any task it is his taste. – Hynek -Pichi- Vychodil Aug 06 '10 at 20:02
  • I know a bit of Erlang it rocks, but I'd prefer to use Python. I need not to to the same thing I do in Erlang in Python, and also not in the same way – daitangio Aug 07 '10 at 14:41

6 Answers6

20

To make actors with gevent, use a Greenlet subclass with embedded gevent.queue.Queue instance used as an inbox. To read a message from the inbox, simply get() from the queue. To send a message to an actor, put it into that actor's queue.

Read about subclassing Greenlet here.

If you need help with writing the Actor class, feel free to ask the mailing list.

Denis
  • 3,760
  • 25
  • 22
15

Check out pulsar, it is a concurrent framework for python which uses the actor model as source of parallel execution.

Luca Sbardella
  • 1,114
  • 9
  • 13
11

I know this question is a bit dated but here is another actor resource for python now:

https://github.com/godaddy/Thespian

Documentation can be found here:

http://godaddy.github.io/Thespian/doc/

EDIT:

The primary author of this library has since left GoDaddy and forked the repo:

https://github.com/kquick/Thespian

New docs can be found here:

http://thespianpy.com/doc/

beardedeagle
  • 762
  • 1
  • 11
  • 24
5

PARLEY and Pykka are listed on this Wikipedia Actor Model page so you might want to look into one of those.

Pykka seems to be actively developed (1.0.1 released in Dec 2012) whereas PARLEY hasn't had a release since 2007 (and is still listed as beta) . Pykka claims to be insipired by Akka only in name is not a simply a python port.

David
  • 4,486
  • 1
  • 17
  • 5
  • What confuses me is that in Erlang, it's very common for actors to message themselves. In Pykka it's not clear how an object gets a reference of itself. – fatuhoku Sep 01 '13 at 20:20
  • 1
    Not sure how new this feature is, but Pykka 1.2.0 supports self.actor_ref. This is explicitly mentioned in the [Proxies section](http://www.pykka.org/en/latest/api/#proxies) of the docs as a way for an actor to "schedule future work" with itself, so I'd imagine that's strongly supported. – Jayson Feb 21 '14 at 02:55
  • looks like pykka no longer actively developed – Andy Hayden Oct 30 '16 at 18:20
  • Last commit in March 2019, looks it's still in development. ;) – andreas Apr 29 '19 at 14:56
3

I would take a look at this: https://bitbucket.org/fzzzy/python-actors

It's pretty much a straight clone of the Erlang actor model, with "saved" messages queue, links and everything.

jrydberg
  • 579
  • 5
  • 14
3

This tutorial has a simple and working example for actors with gevent. Basically it's exactly as Denis already described.

Michael
  • 7,316
  • 1
  • 37
  • 63