[zeromq-dev] PUB-SUB works, server restarts, PUB-SUB fails for existing workers.

alotsof alotsof at gmx.net
Wed Aug 31 21:05:04 CEST 2011

> The subprocess.Popen call most likely is using popen(), which uses fork() and
> that will cause the child process to inherit the parent's set of open file
> descriptors.  This means that the child process is keeping the server socket
> alive even when the parent closes the socket or dies.
> One way to test this is to check if the server socket is still in the LISTEN
> state and owned by the worker process.
> Run: netstat -pln | grep tcp
> Look for the socket bound to your server's tcp port.  You can also grep for
> your worker's pid.

yes, once the server dies, the socket is owned by the worker process.

So it comes down to another episode of fork vs. threads. From the 
reading I've just done following your tip, the general opinion is:

	DON'T (mix fork and threads)

> Do what Pieter said and start the worker from a shell script as a separate
> process (i.e. not a child of the server).
> Or if you really need to start the workers from the server process, the use a
> wrapper script to daemonize (fork + execve) the worker process.

Yes, with a wrapper, the reconnection problem goes away.

Many thanks.

More information about the zeromq-dev mailing list