import os, signal, time from mex.hub import Hub from mex.msg import Msg from mex.node import Node from utils.forked import Forked h = Hub (min_clients = 3) fh = Forked (h.wait) n = Node () def nf (): while True: time.sleep (1) n.wait (n.date + 1000) fn = Forked (nf) slave = os.popen ('./slave/test_twi_slave.host', 'w') try: os.system ('./master/test_twi_master.host') finally: fn.kill () fh.kill () slave.close () time.sleep (1)
f1 = Forked (c1) def c2 (): n = Node () mtype_oucouc = n.reserve ('oucouc') mtype_coucou = n.reserve ('coucou') def a (msg): print 'coucou' n.register (mtype_coucou, a) m = Msg (mtype_oucouc) m.push ('B', 42) r = n.request (m) assert r.mtype == mtype_oucouc assert r.pop ('B') == (43,) n.wait_async (42) while not n.sync (): fds = select.select ((n, ), (), ())[0] for i in fds: i.read () n.wait () f2 = Forked (c2) try: h.wait () finally: f1.kill () f2.kill () import time time.sleep (1)