Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supervision #42

Open
drozzy opened this issue Aug 12, 2014 · 1 comment
Open

Supervision #42

drozzy opened this issue Aug 12, 2014 · 1 comment

Comments

@drozzy
Copy link

drozzy commented Aug 12, 2014

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?

@jodal
Copy link
Owner

jodal commented Aug 12, 2014

Thanks for providing a good howto on how to implement a supervision pattern yourself. Supervision is mostly lacking from Pykka because of time/effort/need, and not because I oppose it. I'm interested in including it in a future Pykka 2.

I'll leave this bug open to either add the pattern to docs or to use it as basis for some future supervision support

@jodal jodal added the wishlist label Aug 12, 2014
@jodal jodal added this to the v2.0 milestone Aug 12, 2014
@jodal jodal removed this from the v2.0 milestone Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants