Please explain Zeromq eventloop
How is different from multiplexing several sockets via a POLLIN?
while True:
socks = dict(poller.poll())
if socks.get(control_receiver) == zmq.POLLIN:
...
if socks.get(work_receiver) == zmq.POLLIN:
...
How can it make listener threads more reliable and easier to h开发者_开发问答andle?
Background: I am rolling my own API server and wondering how to make the controller (the part that receives the requests from external source and control signals from the workers)
ØMQ Poller can be used to serve and communicate with multiple sockets.
How ever, with ØMQ Poller, you end up with explicit blocks (under if loop) for handling the sockets. Each socket registered with ØMQ Poller has to have an explicit “if block” to handle it.
This becomes unwieldy as you start writing bigger programs. I would like to add - "a bit ugly"
With Event Loops, this becomes more streamlined as you can register callbacks to receive and send data and you can structure your callback else where.
I have following examples from the tutorial that I am writing.
- http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/zmqpoller.html
- http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/tornadoeventloop.html
Others can add on to this understanding or correct it.
精彩评论