forked from circuits/circuits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_multi_bridge.py
executable file
·56 lines (35 loc) · 1.09 KB
/
hello_multi_bridge.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
"""Multi Bridge Example
Identical to the Hello Bridge Example but with a 2nd child.
"""
from __future__ import print_function
from os import getpid
from circuits import Component, Event, ipc
class go(Event):
"""go Event"""
class hello(Event):
"""hello Event"""
class Child(Component):
def hello(self):
return "Hello from child with pid {0}".format(getpid())
class App(Component):
def init(self):
self.counter = 0
self.child1 = Child().start(process=True, link=self)
self.child2 = Child().start(process=True, link=self)
def ready(self, *args):
self.counter += 1
if self.counter < 2:
return
self.fire(go())
def go(self):
x = yield self.call(hello())
yield print(x)
y = yield self.call(ipc(hello()), self.child1[1].channel)
yield print(y)
z = yield self.call(ipc(hello()), self.child2[1].channel)
yield print(z)
raise SystemExit(0)
def hello(self):
return "Hello from parent with pid {0}".format(getpid())
App().run()