eventletとzeromqPUSH/PULLソケットを使用してリスナー/送信者のペアを作成しようとしています。
これはコードです:
import eventlet
from eventlet.green import zmq
from eventlet import sleep as gsleep
#===============================================================================
# config
#===============================================================================
ctx = zmq.Context()
adr = 'tcp://127.0.0.1:5558'
#===============================================================================
# listener
#===============================================================================
def listen(addr):
l = ctx.socket(zmq.PULL)
l.connect(addr)
print 'listening on %s' % addr
while True:
data = l.recv()
print 'something received : %s' % data
eventlet.spawn_n(listen, adr)
#===============================================================================
# sender
#===============================================================================
s = ctx.socket(zmq.PUSH)
s.connect(adr)
while True:
gsleep(1)
print "sending something"
s.send('blabla')
出力を取得しています:
listening on tcp://127.0.0.1:5558
sending something
sending something
sending something
sending something
sending something
sending something
...
期待される代わりに:
listening on tcp://127.0.0.1:5558
sending something
something received : blabla
sending something
something received : blabla
sending something
something received : blabla
...
私は何が欠けていますか?