Python zmq.eventloop() Examples

The following are 8 code examples of zmq.eventloop(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module zmq , or try the search function .
Example #1
Source File: test_future.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_recv_json_cancelled(self):
        @gen.coroutine
        def test():
            a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
            f = b.recv_json()
            assert not f.done()
            f.cancel()
            # cycle eventloop to allow cancel events to fire
            yield gen.sleep(0)
            obj = dict(a=5)
            yield a.send_json(obj)
            with pytest.raises(future.CancelledError):
                recvd = yield f
            assert f.done()
            # give it a chance to incorrectly consume the event
            events = yield b.poll(timeout=5)
            assert events
            yield gen.sleep(0)
            # make sure cancelled recv didn't eat up event
            recvd = yield gen.with_timeout(timedelta(seconds=5), b.recv_json())
            assert recvd == obj
        self.loop.run_sync(test) 
Example #2
Source File: ipkernel.py    From Computable with MIT License 6 votes vote down vote up
def enter_eventloop(self):
        """enter eventloop"""
        self.log.info("entering eventloop")
        # restore default_int_handler
        signal(SIGINT, default_int_handler)
        while self.eventloop is not None:
            try:
                self.eventloop(self)
            except KeyboardInterrupt:
                # Ctrl-C shouldn't crash the kernel
                self.log.error("KeyboardInterrupt caught in kernel")
                continue
            else:
                # eventloop exited cleanly, this means we should stop (right?)
                self.eventloop = None
                break
        self.log.info("exiting eventloop") 
Example #3
Source File: test_future.py    From pySINDy with MIT License 6 votes vote down vote up
def test_recv_json_cancelled(self):
        @gen.coroutine
        def test():
            a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
            f = b.recv_json()
            assert not f.done()
            f.cancel()
            # cycle eventloop to allow cancel events to fire
            yield gen.sleep(0)
            obj = dict(a=5)
            yield a.send_json(obj)
            with pytest.raises(future.CancelledError):
                recvd = yield f
            assert f.done()
            # give it a chance to incorrectly consume the event
            events = yield b.poll(timeout=5)
            assert events
            yield gen.sleep(0)
            # make sure cancelled recv didn't eat up event
            recvd = yield gen.with_timeout(timedelta(seconds=5), b.recv_json())
            assert recvd == obj
        self.loop.run_sync(test) 
Example #4
Source File: test_imports.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_eventloop(self):
        """test eventloop imports"""
        try:
            import tornado
        except ImportError:
            pytest.skip('requires tornado')
        import zmq.eventloop
        from zmq.eventloop import ioloop
        from zmq.eventloop import zmqstream 
Example #5
Source File: main.py    From backend with GNU General Public License v2.0 5 votes vote down vote up
def run_application(options, instance_name):
  from zmq.eventloop import ioloop
  ioloop.install()

  application = WebSocketGatewayApplication(options, instance_name)

  server = tornado.httpserver.HTTPServer(application)
  server.listen(options.port)

  try:
    tornado.ioloop.IOLoop.instance().start()
  except KeyboardInterrupt:
    application.clean_up() 
Example #6
Source File: ipkernel.py    From Computable with MIT License 5 votes vote down vote up
def _eventloop_changed(self, name, old, new):
        """schedule call to eventloop from IOLoop"""
        loop = ioloop.IOLoop.instance()
        loop.add_timeout(time.time()+0.1, self.enter_eventloop) 
Example #7
Source File: ipkernel.py    From Computable with MIT License 5 votes vote down vote up
def do_one_iteration(self):
        """step eventloop just once"""
        InteractiveShell.set_instance(self.shell)
        if self.control_stream:
            self.control_stream.flush()
        for stream in self.shell_streams:
            # handle at most one request per iteration
            stream.flush(zmq.POLLIN, 1)
            stream.flush(zmq.POLLOUT) 
Example #8
Source File: test_imports.py    From pySINDy with MIT License 5 votes vote down vote up
def test_eventloop(self):
        """test eventloop imports"""
        try:
            import tornado
        except ImportError:
            pytest.skip('requires tornado')
        import zmq.eventloop
        from zmq.eventloop import ioloop
        from zmq.eventloop import zmqstream