Skip to content

Instantly share code, notes, and snippets.

@bombela
Created August 6, 2012 18:59
Show Gist options
  • Save bombela/3277557 to your computer and use it in GitHub Desktop.
Save bombela/3277557 to your computer and use it in GitHub Desktop.
stress PyZMQ to trigger the 'missing event' problem
#!/usr/bin/env python
import zerorpc.gevent_zmq as zmq
context = zmq.Context()
c = zmq.Socket(context, zmq.XREQ)
c.connect('tcp://127.0.0.1:9998')
print 'running'
while True:
c.send('', flags=zmq.SNDMORE)
c.send('ping')
msg = c.recv()
assert msg == 'maybe'
#!/usr/bin/env python
import zerorpc.gevent_zmq as zmq
import gevent
context = zmq.Context()
c = zmq.Socket(context, zmq.XREQ)
c.connect('tcp://127.0.0.1:9999')
s = zmq.Socket(context, zmq.XREP)
s.bind('tcp://127.0.0.1:9998')
def task(zmqid, msg):
c.send('', flags=zmq.SNDMORE)
c.send('ping')
msg = c.recv()
s.send(zmqid, flags=zmq.SNDMORE)
s.send(msg)
print 'running'
while True:
zmqid = s.recv()
s.recv()
msg = s.recv()
gevent.spawn(task, zmqid, msg)
#!/usr/bin/env python
import zerorpc.gevent_zmq as zmq
context = zmq.Context()
s = zmq.Socket(context, zmq.XREP)
s.bind('tcp://127.0.0.1:9999')
print 'running'
while True:
zmqid = s.recv()
s.recv()
msg = s.recv()
s.send(zmqid, flags=zmq.SNDMORE)
s.send('maybe')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment