Skip to content

Instantly share code, notes, and snippets.

@tailhook
Created December 12, 2010 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tailhook/738221 to your computer and use it in GitHub Desktop.
Save tailhook/738221 to your computer and use it in GitHub Desktop.
test.py
import sys
import zmq
import time
import subprocess
import atexit
ctx = zmq.Context(1)
sock = ctx.socket(zmq.XREQ)
sock.bind('tcp://127.0.0.1:12345')
proc = subprocess.Popen([sys.executable, 'test2.py'])
time.sleep(0.1)
proc1 = subprocess.Popen([sys.executable, 'test2.py'])
atexit.register(proc1.terminate)
time.sleep(0.1)
sock.send(b"a1", zmq.SNDMORE)
time.sleep(0.1)
proc.terminate()
proc.wait()
time.sleep(0.1)
sock.send(b"b1", zmq.SNDMORE|zmq.NOBLOCK)
time.sleep(0.1)
proc = subprocess.Popen([sys.executable, 'test2.py'])
time.sleep(0.1)
sock.send(b"c1", zmq.NOBLOCK)
sock.send(b"a2", zmq.SNDMORE|zmq.NOBLOCK)
sock.send(b"b2", zmq.SNDMORE|zmq.NOBLOCK)
sock.send(b"c2", zmq.NOBLOCK)
sock.send(b"a3", zmq.SNDMORE|zmq.NOBLOCK)
sock.send(b"b3", zmq.SNDMORE|zmq.NOBLOCK)
sock.send(b"c3", zmq.NOBLOCK)
try:
proc.wait()
except:
proc.terminate()
finally:
proc1.terminate()
ctx = zmq.Context(1)
import zmq
import time
ctx = zmq.Context(1)
sock = ctx.socket(zmq.XREP)
sock.connect('tcp://127.0.0.1:12345')
while True:
print("MSG", sock.recv_multipart())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment