EzDevInfo.com

pykka

Pykka is a Python implementation of the actor model, which makes it easier to build concurrent applications Pykka — Pykka 1.2.1 documentation

Using Akka actors to invoke or pass messages to Python code

I've a some analysis code that's written in Python. Currently I'm using Storm to process streams. Because Storm allows invocation of python code using message serialization I an invoke Python code from Java/Scala in my Storm bolts.

I found Pykka which is a Python implementation of the actor model. I was wondering if there is a way to invoke Python code from Akka actors? For example, is it possible to pass message from Akka actors to Pykka actors ?


Source: (StackOverflow)

How to make Pykka log directly to console?

Pykka logs to a logger called pykka. I want all exceptions, debug messages printed to console, especially when running tests that start and stop actors in Pykka written with Mamba.

How do I do this?


Source: (StackOverflow)

Advertisements

Pykka: get the base class of an Actor

I use pykka python library. I would like to create an actor, and later test if the actor created is of the proper class.

class MyActor( ThreadingActor ):
  # ...

actor = MyActor.start().proxy()

assert actor.__class__ == MyActor # check here?

Here actor.__class__ is pykka.actor.ActorRef. How to check if it refers to MyActor class? I need it for a unit test suite.


Source: (StackOverflow)

pykka -- Actors are slow?

I am currently experimenting with Actor-concurreny (on Python), because I want to learn more about this. Therefore I choosed pykka, but when I test it, it's more than half as slow as an normal function.

The Code is only to look if it works; it's not meant to be elegant. :)

Maybe I made something wrong?

from pykka.actor import ThreadingActor
import numpy as np

class Adder(ThreadingActor):
    def add_one(self, i):
        l = []
        for j in i:
            l.append(j+1)
        return l

if __name__ == '__main__':
    data = np.random.random(1000000)
    adder = Adder.start().proxy()
    adder.add_one(data)
    adder.stop()

This runs not so fast:

time python actor.py

real    0m8.319s
user    0m8.185s
sys     0m0.140s

And now the dummy 'normal' function:

def foo(i):
    l = []
    for j in i:
        l.append(j+1)
    return l

if __name__ == '__main__':
    data = np.random.random(1000000)
    foo(data)

Gives this result:

real    0m3.665s
user    0m3.348s
sys     0m0.308s

Source: (StackOverflow)

Pykka: How to cancel an actor's pending messages queue when it has been stopped

I've playing with Pykka actors library and I came up with the following awesome silly example:

import pykka
from time import sleep

class TestActor(pykka.ThreadingActor):
    def on_receive(self, message):
        sleep(1)
        print(message["v"])    

a = TestActor.start()
for i in xrange(10):
    print("asking for " + str(i))
    a.tell({"v":i})
print(a.stop())

I get the expected result: 10 asking for lines which are printed immediately and another 10 lines each printed in 1 second time period:

asking for 0
asking for 1
asking for 2
asking for 3
asking for 4
asking for 5
asking for 6
asking for 7
asking for 8
asking for 9
0
1
2
3
4
5
6
7
8
9
True

After all the requests have been served by the actor, True is printed as the result of the stop action.

I wonder if it would be possible to stop the actor thus cancelling the reception and processing of the reamining messages.

I've checked the library documentation but all I can find is the block stop parameter which means a quite different thing: When set to False it makes the call to be asynchronous but its behaviour concerning the message queue is the same:

stop(block=True, timeout=None)

Send a message to the actor, asking it to stop.

Returns True if actor is stopped or was being stopped at the time of the call. False if actor was already dead. If block is False, it returns a future wrapping the result.

Messages sent to the actor before the actor is asked to stop will be processed normally before it stops.

Messages sent to the actor after the actor is asked to stop will be replied to with pykka.ActorDeadError after it stops.

The actor may not be restarted.

block and timeout works as for ask().

Returns: pykka.Future, or a boolean result if blocking


Source: (StackOverflow)

An actor-based GUI with Pykka and PyQt

Background:

This is really an architecture question.

I'm looking to port an application currently written in LabView to Python. It is a hardware control and measurement application which basically orchestrates a bunch of heterogeneous hardware to run tests.

I'm considering basing the Python application on Pykka, since an actor abstraction seems particularly suitable for orchestrating a bunch of parallel hardware tasks (the LabView app uses the LV Actor Framework).

The application needs a GUI -- PyQt and PyQtGraph are extremely promising here.

Problem

Pykka and PyQt are built around event loops and have different ideas about threading and inter-thread communication. I'm uncertain how I could structure code to let a Pykka actor display an interface using PyQt. I've played with modifying the Pykka event loop to call PyQt's processEvents(), with subclassing pykka.Actor such that it's implemented with QProcess, and with having a Pykka actor hold a reference to a standalone thread. I haven't been able to come up with a satisfying result, and it's because I'm somewhat new to both libraries.

How can I build a Pykka actor that displays and manages a PyQt GUI?

(p.s. Answers of "You're Crazy" are welcomed!)


Source: (StackOverflow)