开发者

Please explain Zeromq eventloop

开发者 https://www.devze.com 2023-04-08 18:33 出处:网络
How is different from multiplexing several sockets via a POLLIN? while True: socks = dict(poller.poll())

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.

  1. http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/zmqpoller.html
  2. http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/tornadoeventloop.html

Others can add on to this understanding or correct it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号