Created
July 10, 2013 14:10
-
-
Save dwt/5966606 to your computer and use it in GitHub Desktop.
Reproduction of bug https://github.com/guidog/pyzmq-mdp/issues/8
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 zmq | |
from zmq.eventloop.ioloop import IOLoop | |
from broker import MDPBroker | |
class MyBroker(MDPBroker): | |
pass | |
if __name__ == '__main__': | |
context = zmq.Context() | |
broker = MyBroker(context, "tcp://127.0.0.1:5555") | |
IOLoop.instance().start() | |
broker.shutdown() | |
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 zmq | |
from zmq.eventloop.ioloop import IOLoop | |
from client import MDPClient, mdp_request | |
class MyClient(MDPClient): | |
def on_message(self, msg): | |
if len(msg) <= 2: | |
print "Got empty reply" | |
return | |
print("Reply:", repr(msg)) | |
def on_timeout(self): | |
print 'TIMEOUT!' | |
if __name__ == '__main__': | |
context = zmq.Context() | |
for game_id in range(12): | |
client = MyClient(context, "tcp://127.0.0.1:5555", b'worker') | |
print("sending request for game_id", game_id) | |
client.request([str(game_id)], timeout=2000) | |
print "sent all requests" | |
IOLoop.instance().start() | |
socket.close() | |
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
# -*- coding: utf-8 -*- | |
import zmq | |
from zmq.eventloop.ioloop import IOLoop | |
from worker import MDPWorker | |
import time | |
class MyWorker(MDPWorker): | |
HB_INTERVAL = 1000 | |
HB_LIVENESS = 3 | |
count = 0 | |
def on_request(self, msg): | |
import random | |
time.sleep(random.randint(1,5)) | |
self.reply(["%s" % range(random.randint(400,10000))]) | |
if __name__ == '__main__': | |
context = zmq.Context() | |
worker = MyWorker(context, "tcp://127.0.0.1:5555", b"worker") | |
IOLoop.instance().start() | |
worker.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment