Skip to content

Supervision #42

Description

@drozzy

Currently, the only way to know that the "child" actor failed, is to employ the 'ask' pattern:

actor = MyActor.start()
try:
      actor.ask({'command':'hey'})
except Exception:
      # actor failed!

However, if we are using tell, the is no way to "detect" a failure:

actor.tell({'command':'throw me an exception!'})
# Everything is great!

Akka handles this by registering an actor for "death watch":
http://doc.akka.io/docs/akka/snapshot/general/supervision.html

In pykka we can implement a similar thing manually by providing an actor with a parent argument and overriding on_failure in the MyActor:

class MyActor(ThreadingActor):
    def __init__(self, parent):
        super(MyActor, self).__init__()
        self.parent = parent

    def on_failure(self, exception_type, exception_value, traceback):
        self.parent.tell({'command': 'death', 'exception': exception_value})

Then the parent actor would simply have to handle it, like so:

class Parent(ThreadingActor):
    def __init__(self, parent):
        super(Parent, self).__init__()
        self.child = MyActor.start(parent=self.actor_ref)

    def on_receive(self, message):
        if message.get('command') == 'death:            
            # Child actor died....
            if not self.child.is_alive():
                # restart it...
                self.child = MyActor.start(parent=self.actor_ref)

P.S.: On the readme page, where it says what "pykka is not" --- supervision is one of the mentions.
Is there any specific reasons (aside from time/effort) that its not? I.e. are you opposed to the idea?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions