Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pyzmq multipart atomicity issue
import os
from time import monotonic
import zmq
# Set up a PULL socket
ctx = zmq.Context()
sock = ctx.socket(zmq.PULL)
sock.set_hwm(1)
sock.connect("tcp://127.0.0.1:8541")
# Receive just before exiting
t0 = monotonic()
msg = sock.recv_multipart()
td = monotonic() - t0
print("Received", len(msg), "parts in", td, "seconds")
from itertools import count
import zmq
# Set up a PUSH socket
ctx = zmq.Context()
sock = ctx.socket(zmq.PUSH)
sock.set_hwm(1)
sock.bind("tcp://127.0.0.1:8541")
# Send multipart messages containing 512 MB data
data = b'a' * 512 * 1024 * 1024
try:
for i in count():
sock.send_multipart([str(i).encode(), data])
print('sent', i)
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.