예제 #1
0
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)
예제 #2
0
class Pinger(Actor):
    def on_start(self):
        self.child = ActorSystem().create(Ponger)

    def on_receive(self, message, sender):
        self.sleep(0)
        future = self.child.ask(message)

        future.on_ready(self._print)

    @staticmethod
    def _print(v):
        print v
예제 #3
0
 def on_start(self):
     self.count = 0
     self.pong = ActorSystem().create(Ponger)
예제 #4
0
    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)
예제 #5
0
 def on_start(self):
     self.child = ActorSystem().create(Ponger)
예제 #6
0

class Pinger(Actor):
    def on_start(self):
        self.child = ActorSystem().create(Ponger)

    def on_receive(self, message, sender):
        self.sleep(0)
        future = self.child.ask(message)

        future.on_ready(self._print)

    @staticmethod
    def _print(v):
        print v


class Ponger(Actor):
    def on_receive(self, message, sender):
        self.sleep(1)
        return message + 1


if __name__ == "__main__":
    ping = ActorSystem().create(Pinger)
    ping.tell(1, None)
    print "start"
    ActorSystem().sleep(5)

    # TODO: become, unbecome 구현