You are encountering ZeroMQ's LINGER behaviour. LINGER defines how long the Context should wait before allowing Context.term
to discard messages. The default in ZeroMQ 2.x is forever, and the default in ZeroMQ 3.x is one second. If you tell your sockets that they should only linger a short time, your script should exit just fine:
socket = context.socket(zmq.REQ)
socket_id = randomID()
socket.identity = ramdomID()
socket.linger = 250 # 250ms = 1/4 s
socket.connect("tcp://dead_server")