Skip to content

Instantly share code, notes, and snippets.

@lsbardel
Created December 24, 2013 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lsbardel/8111173 to your computer and use it in GitHub Desktop.
Save lsbardel/8111173 to your computer and use it in GitHub Desktop.
An actor greeting the arbiter
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