Created
December 24, 2013 10:06
-
-
Save lsbardel/8111173 to your computer and use it in GitHub Desktop.
An actor greeting the arbiter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pulsar import arbiter, command | |
names = ['john', 'luca', 'carl', 'jo', 'alex'] | |
@command() | |
def greetme(request, message): | |
echo = 'Hello {}!'.format(message['name']) | |
request.actor.logger.info(echo) | |
return echo | |
def interact(actor, a=None): | |
if a is None: | |
a = yield actor.spawn(name='greeter') | |
if names: | |
name = names.pop() | |
msg = yield actor.send(a, 'greetme', {'name': name}) | |
actor._loop.call_later(1, interact, actor, a) | |
else: | |
actor.stop() | |
def onstart(actor): | |
actor._loop.call_soon(interact, actor) | |
return actor | |
if __name__ == '__main__': | |
arbiter(start=onstart).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment