/
main3.py
41 lines (27 loc) · 807 Bytes
/
main3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
from Actor2.Actor import Actor
from Actor2.Actor import ActorSystem
class Pinger(Actor):
def on_start(self):
self.count = 0
self.pong = ActorSystem().create(Ponger)
def on_receive(self, message, sender):
print(message, self.count)
if sender is None:
self.pong.tell('+', self)
else:
sender.tell('+', self)
self.count += 1
self.sleep(0)
class Ponger(Actor):
def on_start(self):
self.count = 0
def on_receive(self, message, sender):
print(message, self.count)
sender.tell('-', self)
self.count += 1
self.sleep(0)
if __name__ == "__main__":
ping = ActorSystem().create(Pinger)
ping.tell('start', None)
ActorSystem().sleep(1)