Skip to content

Instantly share code, notes, and snippets.

@moriyoshi
Forked from ymotongpoo/calcpull.py
Created March 28, 2012 05:36
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 moriyoshi/2223931 to your computer and use it in GitHub Desktop.
Save moriyoshi/2223931 to your computer and use it in GitHub Desktop.
ZeroMQ PUSH/PULL sample implementation (no collector)
import zmq
import sys
import time
cxt = zmq.Context()
receiver = cxt.socket(zmq.PULL)
receiver.connect("tcp://127.0.0.1:5555")
sum = 0
while True:
message = receiver.recv()
sum += int(message)
print "worker %s: sum = %d" % (sys.argv[1], sum)
time.sleep(0.5)
import zmq
import time
from random import randrange
cxt = zmq.Context()
sender = cxt.socket(zmq.PUSH)
sender.bind("tcp://127.0.0.1:5555")
time.sleep(10)
sum = 0
for i in range(1000):
value = randrange(5000)
sum += value
print i, value
sender.send(str(value))
print "sum is %d" % sum
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment