Esempio n. 1
0
    def connect_to_server(self, server):
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.DEALER)

        tmpdir = tempfile.gettempdir()
        connection_string = 'ipc://%s/%s_%s' % (tmpdir, 'zmq', server)
        self.socket.connect(connection_string)

        io_loop = ioloop.IOLoop(ioloop.ZMQPoller())

        self.stream = ZMQStream(self.socket, io_loop)

        # create partial function that has self as first argument
        callback = partial(_on_recv, self)
        self.stream.on_recv(callback)
        self.event_loop = EventLoop(io_loop)
        self.event_loop.start()
 def test_poller_events(self):
     """Tornado poller implementation maps events correctly"""
     req,rep = self.create_bound_pair(zmq.REQ, zmq.REP)
     poller = ioloop.ZMQPoller()
     poller.register(req, ioloop.IOLoop.READ)
     poller.register(rep, ioloop.IOLoop.READ)
     events = dict(poller.poll(0))
     self.assertEqual(events.get(rep), None)
     self.assertEqual(events.get(req), None)
     
     poller.register(req, ioloop.IOLoop.WRITE)
     poller.register(rep, ioloop.IOLoop.WRITE)
     events = dict(poller.poll(1))
     self.assertEqual(events.get(req), ioloop.IOLoop.WRITE)
     self.assertEqual(events.get(rep), None)
     
     poller.register(rep, ioloop.IOLoop.READ)
     req.send(b'hi')
     events = dict(poller.poll(1))
     self.assertEqual(events.get(rep), ioloop.IOLoop.READ)
     self.assertEqual(events.get(req), None)