I have a problem in closing python application while I using ZeroMQ. first I connect to a server that is not running!
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket_id = randomID()
socket.setsockopt(zmq.IDENTITY, socket_id)
socket.connect("tcp://dead_server")
poller = zmq.Poller()
poller.register(socket, zmq.POLLIN)
and sending my message
socket.send(msg)
waiting for reply
sockets = dict(poller.poll(1000))
if sockets.get(socket) == zmq.POLLIN:
result = socket.recv()
print (result)
so the server is dead the message will be not send and there is no reply. it is work true. then I close socket and unregister it from poller then connect to alive server with new socket and I send message by the socket and get reply from it.
poller.unregister(socket)
socket.close()
socket = context.socket(zmq.REQ)
socket.setsockopt(zmq.IDENTITY, socket_id)
poller.register(socket, zmq.POLLIN)
socket.connect("tcp://alive_server")
socket.send(msg)
sockets = dict(poller.poll(1000))
if sockets.get(socket) == zmq.POLLIN:
result = socket.recv()
print (result)
# Every thing ok up to hear
after it the application (python script) is not closed (terminate)! it is my problem. [I can close application with sig_term
but i won't to use it for some reason.]
if I don't send first message to dead server the application is closed truly. I guess the problem is ZeroMQ io thread but I can't solve it.
exit(0) # Not worked
sys.exit(0) # Not worked