Skip to content

Instantly share code, notes, and snippets.

@hiway
Last active March 23, 2017 15:32
Show Gist options
  • Save hiway/5ffcc3438637d8942cab2e46e8520fce to your computer and use it in GitHub Desktop.
Save hiway/5ffcc3438637d8942cab2e46e8520fce to your computer and use it in GitHub Desktop.
from zentropi import Agent
from zentropi import on_timer
from zentropi import on_message
class Leonidas(Agent):
@on_timer(3)
def ping(self):
self.message('Spartans?')
class Spartan(Agent):
@on_message('Spartans?')
def pong(self, message):
if message.source != 'King Leonidas':
return None
return 'Ahoo!'
spartans = []
leonidas = Leonidas(name='King Leonidas')
leonidas.bind('inmemory://')
leonidas.join('Thermopylae')
for x in range(300):
name = 'Spartan-{}'.format(x)
spartan = Spartan(name=name)
spartans.append(spartan)
spartan.attach(leonidas)
spartan.connect('inmemory://')
spartan.join('Thermopylae')
leonidas.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment