-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexperimental.py
More file actions
42 lines (30 loc) · 950 Bytes
/
experimental.py
File metadata and controls
42 lines (30 loc) · 950 Bytes
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
from osbrain import run_agent
from osbrain import run_nameserver
import multiprocessing
def method_a(agent, message):
gg = mpns.temp
gg = 10
agent.log_info('Method A Temp: %s' % mpns.temp)
return 'Blah 1'
def method_b(agent, message):
agent.log_info('Method B Temp: %s' % mpns.temp)
return 'Blah 2'
if __name__ == '__main__':
manager = multiprocessing.Manager()
global mpns
mpns = manager.Namespace()
mpns.temp = 1
ns = run_nameserver()
alice = run_agent('Alice')
bob = run_agent('Bob')
addr1 = alice.bind('REP', alias='main1', handler=method_a)
addr2 = alice.bind('REP', alias='main2', handler=method_b)
bob.connect(addr1, alias='main1')
bob.send('main1', "Some message")
reply = bob.recv('main1')
bob.connect(addr2, alias='main2')
bob.send('main2', "Some message")
reply = bob.recv('main2')
agents = ns.agents()
print(agents)
ns.shutdown()