Skip to content

Instantly share code, notes, and snippets.

@takluyver
Created December 7, 2018 15:42
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 takluyver/1db6e33ecd5c22c8725437dc60ecb953 to your computer and use it in GitHub Desktop.
Save takluyver/1db6e33ecd5c22c8725437dc60ecb953 to your computer and use it in GitHub Desktop.
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