How to use the zmq.eventloop.ioloop.IOLoop function in zmq

To help you get started, we’ve selected a few zmq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github retresco / Spyder / test / test_fetch_processor_with_etag.py View on Github external
def setUp(self):

        # create the io_loop
        self._io_loop = IOLoop.instance()

        # and the context
        self._ctx = zmq.Context(1)

        # setup the mgmt sockets
        self._setup_mgmt_sockets()

        # setup the data sockets
        self._setup_data_sockets()

        # setup the management interface
        self._mgmt = ZmqMgmt( self._mgmt_sockets['worker_sub'],
            self._mgmt_sockets['worker_pub'], io_loop=self._io_loop)
        self._mgmt.start()
        self._mgmt.add_callback(ZMQ_SPYDER_MGMT_WORKER, self.on_mgmt_end)
github OpenMDAO / OpenMDAO-Framework / openmdao.gui / src / openmdao / gui / zmqstreamserver.py View on Github external
def serve(self):
        ''' Start server listening on port & start the ioloop.
        '''
        DEBUG('serve %s' % self.options.port)
        try:
            if (self.options.external):
                self.http_server.listen(self.options.port)
            else:
                self.http_server.listen(self.options.port, address='localhost')
        except Exception as exc:
            print '<<<%s>>> ZMQStreamServer -- listen on %s failed: %s' \
                  % (os.getpid(), self.options.port, exc)
            sys.exit(1)

        try:
            ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            DEBUG('interrupt received, shutting down.')
github Ulm-IQO / qudi / logic / notebook.py View on Github external
def start(self):
        """ Start the IPython Notebook server app, after initialization
        
        This method takes no arguments so all configuration and initialization
        must be done prior to calling this method."""
        super(NotebookApp, self).start()

        info = self.log.info
        for line in self.notebook_info().split("\n"):
            info(line)
        info("Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).")

        self.write_server_info_file()
        uri = 'tree'
        
        self.io_loop = ioloop.IOLoop.current()
        
        if sys.platform.startswith('win'):
            # add no-op to wake every 5s
            # to handle signals that may be ignored by the inner loop
            pc = ioloop.PeriodicCallback(lambda : None, 5000)
            pc.start()
        try:
            self.io_loop.start()
        except KeyboardInterrupt:
            info("Interrupted...")
        finally:
            self.cleanup_kernels()
            self.remove_server_info_file()
github mike820324 / microProxy / microproxy / viewer / tui.py View on Github external
def __init__(self, config, stream=None, event_loop=None):
        stream = (
            stream or
            create_msg_channel(config["viewer_channel"], "message")
        )
        data_store = MessageAsyncDataStore(stream.on_recv)

        context = gviewer.DisplayerContext(
            data_store, self, actions=gviewer.Actions([
                ("e", "export replay script", self.export_replay),
                ("r", "replay", self.replay),
                ("L", "log", self.log)]))

        self.log_context = LogDisplayer(config).context
        event_loop = event_loop or urwid.TornadoEventLoop(ioloop.IOLoop.instance())
        self.viewer = gviewer.GViewer(
            context, palette=self.PALETTE,
            other_contexts=[self.log_context],
            config=gviewer.Config(auto_scroll=True),
            event_loop=event_loop)
        self.formatter = TuiFormatter()
        self.config = config
        self.event_client = EventClient(config["events_channel"])
        self.terminal_width, _ = get_terminal_size()
github osh / dist_hyperas / dist_hyperas / worker.py View on Github external
def run(self):
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.DEALER)
        self.socket.connect (self.controller_uri)
        self.stream = ZMQStream(self.socket)
        self.stream.on_recv(self.on_rcv)
        self.ioloop = ioloop.IOLoop.instance()
        self.ioloop.add_callback(self.on_start)
        tornado.ioloop.PeriodicCallback(self.on_ping, 1000).start()
        try:
            self.ioloop.start()
        except KeyboardInterrupt:
            self.shutdown()
        self.ioloop.close()
github zeromq / pyzmq / examples / web / frontend.py View on Github external
from zmq.web import (
    ZMQApplicationProxy, ZMQRequestHandlerProxy
)

proxy = ZMQApplicationProxy()
proxy.bind('tcp://127.0.0.1:5555')

application = web.Application(
    # We use a timeout of 2000ms, after which a status of 504 is returned.
    # All URLs beginning with /foo will be handled by the backend.
    [(r"/foo\S*", ZMQRequestHandlerProxy, {'proxy':proxy,'timeout':2000})]
)

logging.info("Starting frontend HTTP server")
application.listen(8888)
ioloop.IOLoop.instance().start()
github yatsu / react-tornado-graphql-example / tornado / tornado_graphql_example / jobserver.py View on Github external
self.zmq_port = zmq_sock.bind_to_random_port('tcp://{0}'.format(self.ip))
        else:
            self.zmq_port = zmq_sock.bind('tcp://{0}:{1}'.format(self.ip, self.port))

        self.zmq_stream = zmqstream.ZMQStream(zmq_sock)
        self.zmq_stream.on_recv(self.request_handler)

        self.log_format = (u'%(color)s[%(levelname)1.1s %(asctime)s.%(msecs).03d '
                           u'%(name)s-{0}]%(end_color)s %(message)s').format(self.pid)
        self.log.info('start %s', self)

        self.write_server_info_file()

        atexit.register(self.remove_server_info_file)

        self.io_loop = ioloop.IOLoop.current()
        try:
            self.io_loop.start()
        except KeyboardInterrupt:
            self.log.info('JobServer interrupted...')
        finally:
            self.remove_server_info_file()
github ipython / ipython / IPython / parallel / logwatcher.py View on Github external
def _loop_default(self):
        return ioloop.IOLoop.instance()
github ymollard / APEX / ros / apex_playground / src / nodes / work_manager.py View on Github external
try:
                type = request['type']
                worker = request['worker']
                if type == 'get':
                    self.socket.send_json(self._cb_get_work(worker))
                elif type == 'update':
                    task, trial, iteration, success = request['task'], request['trial'], request['iteration'], request['success']
                    self.socket.send_json(self._cb_update_work(task, trial, worker, iteration, success))
                else:
                    rospy.logerr("The Work Manager can't handle this request type: '{}'".format(type))
            except (ValueError, KeyError):
                rospy.logerr("The Work Manager can't handle this request: {}".format(request))
                self.socket.send_json({})

        self.context = Context()
        self.loop = ioloop.IOLoop.instance()
        self.socket = self.context.socket(REP)
        self.socket.bind('tcp://127.0.0.1:33589')
        #self.stream = zmqstream.ZMQStream(self.socket, self.loop)
        #self.stream.on_recv(callback_call)
        while not rospy.is_shutdown():
            callback_call(self.socket.recv_json())
        self.loop.stop()
github att / rcloud / rcloud.python / inst / python / rcloud_kernel.py View on Github external
def start(self):
        if self.poller is not None:
            self.poller.start()
        self.kernel.start()
        try:
            ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            pass