[zeromq-dev] PUB-SUB works, server restarts, PUB-SUB fails for existing workers.
alotsof
alotsof at gmx.net
Mon Aug 29 21:03:07 CEST 2011
at this point, the subject line should be something like
"0MQ reconnect problem"
>> Then server and workers can't talk to each other anymore. Workers
>> spawned after the server's restart can communicate with the server...
>
> Does the same happen when you use TCP?
With TCP:
1. if the server starts the worker before setting up 0MQ, no problem. I
can kill and restart the server, and 0MQ reconnects every time.
2. if the server starts the worker *after* setting up 0MQ, then I get
the error message: "Address already in use" when I kill and try to
restart the server.
> You could be hitting a file permissions issue, if you're running the
> server and workers under different user ids.
From the command-line, same user with the code below.
#------------------------------------------------------------------
Usage:
./server5.py -before # starts worker before 0MQ
./server5.py -after # starts worker after 0MQ
Then kill the server, and restart it alone with:
./server5.py # starts server alone
and see when 0MQ reconnects, and when not.
#------------------------------------------------------------------
#!/usr/bin/python
# server5.py
import time
import os
import sys
import subprocess
import zmq
if '-before' in sys.argv:
args =('python','./worker5.py')
p = subprocess.Popen(args)
pid = "server " + str(os.getpid())
context = zmq.Context()
WorkersToServer = context.socket(zmq.PULL)
WorkersToServer.bind("tcp://*:12345")
poller = zmq.Poller()
poller.register(WorkersToServer, zmq.POLLIN)
if '-after' in sys.argv:
args =('python','./worker5.py')
p = subprocess.Popen(args)
while True:
socks = dict(poller.poll(5000))
if WorkersToServer in socks and socks[WorkersToServer] == zmq.POLLIN:
message = WorkersToServer.recv()
print pid, "=", message
else:
print pid, "timeout"
#------------------------------------------------------------------
#!/usr/bin/python
# worker5.py
import time
import os
import zmq
pid = "worker " + str(os.getpid())
context = zmq.Context()
WorkersToServer = context.socket(zmq.PUSH)
WorkersToServer.connect("tcp://localhost:12345")
while True:
WorkersToServer.send(time.ctime() + " from " + pid)
print "\t", pid
time.sleep(1)
More information about the zeromq-dev
mailing list