Created
April 7, 2014 12:07
-
-
Save jcsp/10019073 to your computer and use it in GitHub Desktop.
libzmq issue #962 reproducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zmq | |
import sys | |
def send(payload): | |
""" | |
This emulates the salt SREQ class's __init__() and send() | |
methods, which are called together repeatedly if using | |
Minion._fire_master to send monitoring data. Hopefully | |
we're going to reproduce the ZMQ crash that sometimes happens | |
in that case. | |
""" | |
master = "tcp://{0}:9898".format(sys.argv[1]) | |
timeout = 1 | |
linger = 0 | |
id_ = "" | |
# Initialization | |
# ============== | |
ctx = zmq.Context() | |
sock = ctx.socket(zmq.REQ) | |
if hasattr(zmq, 'RECONNECT_IVL_MAX'): | |
sock.setsockopt( | |
zmq.RECONNECT_IVL_MAX, 5000 | |
) | |
sock.linger = linger | |
if id_: | |
sock.setsockopt(zmq.IDENTITY, id_) | |
sock.connect(master) | |
poller = zmq.Poller() | |
# Transmission | |
# ============ | |
sock.send(payload) | |
poller.register(sock, zmq.POLLIN) | |
while True: | |
polled = poller.poll(timeout * 1000) | |
if polled: | |
break | |
else: | |
print "timeout" | |
return None | |
r = sock.recv() | |
del ctx | |
del poller | |
return r | |
def loop(): | |
while True: | |
send("rhubarb" * 800) | |
if __name__ == "__main__": | |
loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zmq | |
import random | |
def receive(): | |
port = 9898 | |
context = zmq.Context() | |
socket = context.socket(zmq.REP) | |
socket.bind("tcp://*:%s" % port) | |
while True: | |
payload = socket.recv() | |
print "payload: %s..." % payload[0:10] | |
socket.send("OK") | |
if __name__ == "__main__": | |
receive() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment