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

Actor wakeup #38

Closed
dkhan11 opened this issue Mar 14, 2017 · 4 comments
Closed

Actor wakeup #38

dkhan11 opened this issue Mar 14, 2017 · 4 comments

Comments

@dkhan11
Copy link

dkhan11 commented Mar 14, 2017

Hi again,

I'm trying to use the wakeupAfter function with no real success. It works but I might just not understand how it supposed to work...
Example:
class MyActor(Actor):

def receiveMessage(self, message, sender):
    self.wakeupAfter(timedelta(seconds=0.5))

hello = ActorSystem().createActor(MyActor)
ActorSystem().ask(hello, message, 1)

Shouldn't this code just run in a loop forever? I manage to receive the WakupMessage but only if I specify a high timeout for the 'ask', like this:
ActorSystem().ask(hello, message, 10)

What is the right approach for starting an actor and just let it run in a loop without waiting forever for responses? what is the right approach for just starting an actor and let it run forever?

Thanks for the help.
DD.

@dkhan11
Copy link
Author

dkhan11 commented Mar 14, 2017

I have tried to just send the message from the actor, just like you did in your examples:
self.send(self.myAddress, WakeupMessage(timedelta(seconds=2)))

It works but for some reason the delayed period is ignored and it just fires rapidly instead of the 2 seconds delay.
Is this the right way to do so?

Thanks,
DD.

@davinellulinvega
Copy link

davinellulinvega commented Mar 14, 2017

Hello,

Try to simply do something like:

hello = ActorSystem().createActor(MyActor)
ActorSystem().tell(hello, None)  # None is used in place of a real message here

With the implementation of your MyActor class as it is, the first message sent by the ActorSystem will be received immediately by hello and trigger the loop. Subsequent messages should be of type WakeupMessage and trigger further wakeup calls.
Hence, implementing the kind of forever loop you are asking for.

Sincerely.

@dkhan11
Copy link
Author

dkhan11 commented Mar 14, 2017

Got it, thanks! I will use it.

@dkhan11 dkhan11 closed this as completed Mar 14, 2017
@kwquick
Copy link
Contributor

kwquick commented Mar 21, 2017

Thank you @davinellulinvega for providing assistance on this while I was out travelling!

@dkhan11, please feel free to post (either here or on the thespian.py grouplist) if you encounter any additional troubles.

Regards,
Kevin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants