Reputation: 67828
I have a Python program which spawns several other Python programs as subprocesses. One of these subprocesses is supposed to open and bind a ZMQ publisher socket, such that other subprocesses can subscribe to it.
I cannot give guarantees about which tcp ports will be available, so when I bind to a random port in the subprocess, my main program will not know what to tell the other subprocesses.
Is there a way to bind the socket in the main process and then somehow pass the socket to my subprocess? Or either some other way to preregister the socket or a standard way to pass the port information from the subprocess back to my main process (stdout and stderr are already used by other data)?
Just checking for a free port in the main process and passing that to the subprocess is not really optimal, because this could still fail if the socket is being assigned in the meantime. Also, since my program should work on Unix and Windows, I cannot really use ipc sockets, which would otherwise solve my problem.
Upvotes: 0
Views: 529
Reputation: 1
ZeroMQ
sockets to / among other processes ) One may create a persistent, a-priori known, tcp://A.B.C.D:8765
-transport-class based .bind()
access-point, exposed to all client processes as a port-assignment service, to which client processes .connect()
, handshake in whatever manner is needed to proof an identity/credentials/purpose/etc and .recv()
in a coordinated manner one actually free messaging/signalling-service port number, that is system-wide guaranteed to not be used at the very moment / until returned to the port-manager ( a rotating pool of ports is centrally managed, under your code-control, whereas all the sockets, created locally in the distributed process(es)/thread(s) .connect() / .bind()
-ing to the pool-manager announced port#, and thus will still remain, and ought remain, consistently within ZeroMQ
advice, not to be shared per-se ).
Upvotes: 1