Search code examples
pythontornadozeromqpyzmq

How do I run pyzmq and a webserver in one ioloop?


I want to write a single threaded program that hosts a webserver using Tornado and also receive messages on a ZMQ socket (using PyZMQ Tornado event loop: http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/tornadoeventloop.html), but I'm not sure how to structure it. Should I be using

from zmq.eventloop import ioloop

or

from tornado.ioloop import IOLoop

or both?


Solution

  • Before all Tornado imports you need import zmq.eventloop.ioloop and call zmq.eventloop.ioloop.install function. Then you may import Tornado ioloop and use it.

    See: http://zeromq.github.io/pyzmq/eventloop.html