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

Proxy to self as attribute on actor causes deadlock #48

Closed
nmccready opened this issue Nov 12, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@nmccready
Copy link

commented Nov 12, 2014

Your documentation says that referencing your internal proxy is ideal. This is exactly what I want to do, but it hangs every time. It gets out of the constructor and does nothing. Is this a race condition on proxy (internal vs external)?

Details:

  • code below
  • Python 2.7.8
#! /usr/bin/env python
from pykka import ThreadingFuture, ThreadingActor


def go_command():
    actor = HungActor.start()
    proxy = actor.proxy()
    proxy.run()
    actor.stop()


class HungActor(ThreadingActor):
    def __init__(self):
        super(HungActor, self).__init__()
        proxy = self.actor_ref.proxy()
        print proxy
        self.proxy = proxy
        print "out of constructor"

    def run(self):
        print "run"
        self.proxy.a()

    def a(self):
        print "a async"
        self.proxy.b()

    def b(self):
        print "b async"


if __name__ == '__main__':
    # scriptine allows for quick easy scripting
    # where this script will run via `corelogic_data.py command`
    # commands are any def with {SOME_NAME}_command
    import scriptine

    scriptine.run()

to run:
./crap_actor.py go

@nmccready

This comment has been minimized.

Copy link
Author

commented Nov 12, 2014

Here is the same actor but using message passing. This is working.

#! /usr/bin/env python
from pykka import ThreadingFuture, ThreadingActor


def go_command():
    actor = NotHungActor.start()
    proxy = actor.proxy()
    proxy.a()
    # actor.stop()


class NotHungActor(ThreadingActor):
    def __init__(self):
        super(NotHungActor, self).__init__()
        proxy = self.actor_ref.proxy()
        # print proxy
        # self.proxy = proxy
        # print "out of constructor"

    def on_receive(self, message):
        return {
            'run': self.run,
            'a': self.a,
            'b': self.b,
        }[message["msg"]]()

    def run(self):
        print "run"
        self.actor_ref.tell({"msg": "a"})

    def a(self):
        print "a async"
        self.actor_ref.tell({"msg": "b"})

    def b(self):
        print "b async"


if __name__ == '__main__':
    # scriptine allows for quick easy scripting
    # where this script will run via `corelogic_data.py command`
    # commands are any def with {SOME_NAME}_command
    import scriptine

    scriptine.run()
@jodal

This comment has been minimized.

Copy link
Owner

commented Nov 19, 2014

I can't immediately see the source of the problem here. I'll have to experiment a bit with this myself.

@sergunich

This comment has been minimized.

Copy link

commented Apr 26, 2015

I've had similar issue.
In my case problem was in recursive introspection of proxy attribute when I tried to access it.
https://www.pykka.org/en/latest/#actor-proxies
https://www.pykka.org/en/latest/#traversable-attributes-on-proxies

Instead:

# proxy as attr
self.proxy = self.actor_ref.proxy()

#later in code
self.proxy.attr_or_method() #there starts recursive introspection

try to use this:

#method that return proxy
def proxy(self):
    return self.actor_ref.proxy()

#later in code
self.proxy().attr_or_method() #no recursice introspection

kafforch pushed a commit to kafforch/prototype that referenced this issue Dec 17, 2015

@jodal jodal added the question label Dec 8, 2018

@jodal jodal added this to the v2.0 milestone Jan 29, 2019

@jodal jodal changed the title [1.2.0] Internal Proxy self.actor_ref.proxy hangs [blocked] Proxy to self as attribute on actor causes deadlock Jan 29, 2019

@jodal jodal added bug and removed question labels Jan 29, 2019

@jodal jodal self-assigned this Feb 8, 2019

@jodal jodal closed this in 3009215 Feb 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.