Last active
March 23, 2017 15:32
-
-
Save hiway/5ffcc3438637d8942cab2e46e8520fce to your computer and use it in GitHub Desktop.
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 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