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