Пример #1
0
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)
Пример #2
0
        m = Msg (msg.mtype)
        m.push ('B', nb)
        n.response (m)
    n.register ('oucouc', a)
    def b ():
        assert False
    eb = n.schedule (31, b)
    def c ():
        print 'hello'
        n.cancel (eb)
    n.schedule (28, c)
    m = Msg (mtype_coucou)
    n.send (m)
    n.wait ()

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 ():