Skip to content

Instantly share code, notes, and snippets.

@flyer103
Created March 24, 2014 09:20
Show Gist options
  • Save flyer103/9736985 to your computer and use it in GitHub Desktop.
Save flyer103/9736985 to your computer and use it in GitHub Desktop.
简单的 push/pull 例子,本例是 pull.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""简单的 push/pull 例子,本例是 pull.
"""
import time
import random
import zmq
class TestPull(object):
def __init__(self):
self.ctx = zmq.Context()
self.task_rcv = self.ctx.socket(zmq.PULL)
self.task_rcv.connect('tcp://localhost:53000')
self.task_rcv.setsockopt(zmq.RCVHWM, 1)
def run(self):
while True:
msg = self.task_rcv.recv()
print('Receive msg: {0}'.format(msg))
time.sleep(random.randint(2, 3))
if __name__ == '__main__':
test_pull = TestPull()
test_pull.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment