Object A zmq.Poller helps:
def poll_socket(socket, timetick = 100): poller = zmq.Poller() poller.register(socket, zmq.POLLIN)
Then you can do things like:
for message in poll_socket(socket): handle_message(message)
and the for loop will automatically end on Ctrl-C. It seems that the translation from Ctrl-C to Python KeyboardInterrupt occurs only when the interpreter is active and Python has not given control to the low-level C code; the pyzmq recv() call seems to block when using low-level C code, so Python will never get the opportunity to release KeyboardInterrupt. But if you use zmq.Poller , it will stop with a timeout and give the interpreter a chance to release KeyboardInterrupt after the timeout has ended.
source share