Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import zmq
- from multiprocessing import Process
- import time
- SLEEPLEN = .033 # Attempts to approximate a vision system at 30fps
- def src(loc) :
- context = zmq.Context()
- socket = context.socket(zmq.PUB)
- socket.setsockopt(zmq.HWM,1)
- socket.bind(loc)
- while True :
- socket.send( repr(time.time()) ) # Use repr to keep as much precision as possible
- time.sleep(SLEEPLEN)
- def snk(locs) :
- context = zmq.Context()
- socket = context.socket(zmq.SUB)
- socket.setsockopt(zmq.HWM,1)
- socket.setsockopt(zmq.SUBSCRIBE,'')
- for l in locs : socket.connect(l)
- while True :
- print time.time() - float(socket.recv())
- time.sleep(SLEEPLEN)
- def main() :
- addrs = ['ipc:///dev/shm/10001','ipc:///dev/shm/10002','ipc:///dev/shm/10003','ipc:///dev/shm/10004']
- # addrs = ['tcp://*:10001','tcp://*:10002','tcp://*:10003','tcp://*:10004']
- Process( target=snk, args=(addrs,) ).start()
- time.sleep(1)
- for a in addrs : Process( target=src,args=(a,) ).start()
- if __name__ == '__main__' : main()
- else : pass
Advertisement
Add Comment
Please, Sign In to add comment