当前位置: 首页>>代码示例>>Python>>正文


Python zmq.POLLIN属性代码示例

本文整理汇总了Python中zmq.POLLIN属性的典型用法代码示例。如果您正苦于以下问题:Python zmq.POLLIN属性的具体用法?Python zmq.POLLIN怎么用?Python zmq.POLLIN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在zmq的用法示例。


在下文中一共展示了zmq.POLLIN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reconnect_to_broker

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def reconnect_to_broker(self):
        """Connect or reconnect to broker"""
        if self.worker:
            self.poller.unregister(self.worker)
            self.worker.close()
        self.worker = self.ctx.socket(zmq.DEALER)
        self.worker.linger = 0
        self.worker.connect(self.broker)
        self.poller.register(self.worker, zmq.POLLIN)
        if self.verbose:
            logging.info("I: connecting to broker at %s…", self.broker)

        # Register service with broker
        self.send_to_broker(MDP.W_READY, pickle.dumps(self.service), [])

        # If liveness hits zero, queue is considered disconnected
        self.liveness = self.HEARTBEAT_LIVENESS
        self.heartbeat_at = time.time() + 1e-3 * self.heartbeat 
开发者ID:funcx-faas,项目名称:funcX,代码行数:20,代码来源:zmq_worker.py

示例2: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def run(self):
        """Start the Authentication Agent thread task"""
        self.authenticator.start()
        self.started.set()
        zap = self.authenticator.zap_socket
        poller = zmq.Poller()
        poller.register(self.pipe, zmq.POLLIN)
        poller.register(zap, zmq.POLLIN)
        while True:
            try:
                socks = dict(poller.poll())
            except zmq.ZMQError:
                break  # interrupted

            if self.pipe in socks and socks[self.pipe] == zmq.POLLIN:
                terminate = self._handle_pipe()
                if terminate:
                    break

            if zap in socks and socks[zap] == zmq.POLLIN:
                self._handle_zap()

        self.pipe.close()
        self.authenticator.stop() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:thread.py

示例3: _handle_events

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def _handle_events(self, fd, events):
        """This method is the actual handler for IOLoop, that gets called whenever
        an event on my socket is posted. It dispatches to _handle_recv, etc."""
        if not self.socket:
            gen_log.warning("Got events for closed stream %s", fd)
            return
        zmq_events = self.socket.EVENTS
        try:
            # dispatch events:
            if zmq_events & zmq.POLLIN and self.receiving():
                self._handle_recv()
                if not self.socket:
                    return
            if zmq_events & zmq.POLLOUT and self.sending():
                self._handle_send()
                if not self.socket:
                    return

            # rebuild the poll state
            self._rebuild_io_state()
        except Exception:
            gen_log.error("Uncaught exception in zmqstream callback",
                          exc_info=True)
            raise 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:zmqstream.py

示例4: test_poll

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def test_poll(self):
        @asyncio.coroutine
        def test():
            a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
            f = b.poll(timeout=0)
            yield from asyncio.sleep(0)
            self.assertEqual(f.result(), 0)

            f = b.poll(timeout=1)
            assert not f.done()
            evt = yield from f

            self.assertEqual(evt, 0)

            f = b.poll(timeout=1000)
            assert not f.done()
            yield from a.send_multipart([b'hi', b'there'])
            evt = yield from f
            self.assertEqual(evt, zmq.POLLIN)
            recvd = yield from b.recv_multipart()
            self.assertEqual(recvd, [b'hi', b'there'])
        self.loop.run_until_complete(test()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:_test_asyncio.py

示例5: test_poll_base_socket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def test_poll_base_socket(self):
        @asyncio.coroutine
        def test():
            ctx = zmq.Context()
            url = 'inproc://test'
            a = ctx.socket(zmq.PUSH)
            b = ctx.socket(zmq.PULL)
            self.sockets.extend([a, b])
            a.bind(url)
            b.connect(url)

            poller = zaio.Poller()
            poller.register(b, zmq.POLLIN)

            f = poller.poll(timeout=1000)
            assert not f.done()
            a.send_multipart([b'hi', b'there'])
            evt = yield from f
            self.assertEqual(evt, [(b, zmq.POLLIN)])
            recvd = b.recv_multipart()
            self.assertEqual(recvd, [b'hi', b'there'])
        self.loop.run_until_complete(test()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:_test_asyncio.py

示例6: test_timeout

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def test_timeout(self):
        """make sure Poller.poll timeout has the right units (milliseconds)."""
        s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
        poller = self.Poller()
        poller.register(s1, zmq.POLLIN)
        tic = time.time()
        evt = poller.poll(.005)
        toc = time.time()
        self.assertTrue(toc-tic < 0.1)
        tic = time.time()
        evt = poller.poll(5)
        toc = time.time()
        self.assertTrue(toc-tic < 0.1)
        self.assertTrue(toc-tic > .001)
        tic = time.time()
        evt = poller.poll(500)
        toc = time.time()
        self.assertTrue(toc-tic < 1)
        self.assertTrue(toc-tic > 0.1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_poll.py

示例7: test_poll_base_socket

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def test_poll_base_socket(self):
        @gen.coroutine
        def test():
            ctx = zmq.Context()
            url = 'inproc://test'
            a = ctx.socket(zmq.PUSH)
            b = ctx.socket(zmq.PULL)
            self.sockets.extend([a, b])
            a.bind(url)
            b.connect(url)

            poller = future.Poller()
            poller.register(b, zmq.POLLIN)

            f = poller.poll(timeout=1000)
            assert not f.done()
            a.send_multipart([b'hi', b'there'])
            evt = yield f
            self.assertEqual(evt, [(b, zmq.POLLIN)])
            recvd = b.recv_multipart()
            self.assertEqual(recvd, [b'hi', b'there'])
            a.close()
            b.close()
            ctx.term()
        self.loop.run_sync(test) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:test_future.py

示例8: support_test_send_to_multiple_addresses

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def support_test_send_to_multiple_addresses(self, address1, address2):
        poller = zmq.Poller()

        socket1 = self.context.socket(roles['listener'])
        socket2 = self.context.socket(roles['listener'])
        try:
            socket1.bind("tcp://%s" % address1)
            socket2.bind("tcp://%s" % address2)
            poller.register(socket1, zmq.POLLIN)
            poller.register(socket2, zmq.POLLIN)
            polled = dict(poller.poll(2000))
            if socket1 in polled:
                socket1.recv()
                socket1.send(nw0.sockets._serialise(address1))
            elif socket2 in polled:
                socket2.recv()
                socket2.send(nw0.sockets._serialise(address2))
            else:
                raise RuntimeError("Nothing found")
        finally:
            socket1.close()
            socket2.close() 
开发者ID:tjguk,项目名称:networkzero,代码行数:24,代码来源:test_messenger.py

示例9: _abort_queue

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def _abort_queue(self, stream):
        poller = zmq.Poller()
        poller.register(stream.socket, zmq.POLLIN)
        while True:
            idents,msg = self.session.recv(stream, zmq.NOBLOCK, content=True)
            if msg is None:
                return

            self.log.info("Aborting:")
            self.log.info("%s", msg)
            msg_type = msg['header']['msg_type']
            reply_type = msg_type.split('_')[0] + '_reply'

            status = {'status' : 'aborted'}
            md = {'engine' : self.ident}
            md.update(status)
            reply_msg = self.session.send(stream, reply_type, metadata=md,
                        content=status, parent=msg, ident=idents)
            self.log.debug("%s", reply_msg)
            # We need to wait a bit for requests to come in. This can probably
            # be set shorter for true asynchronous clients.
            poller.poll(50) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:ipkernel.py

示例10: _notify_stream_qt

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def _notify_stream_qt(kernel, stream):

    from IPython.external.qt_for_kernel import QtCore

    if _on_os_x_10_9() and kernel._darwin_app_nap:
        from IPython.external.appnope import nope_scope as context
    else:
        from IPython.core.interactiveshell import NoOpContext as context

    def process_stream_events():
        while stream.getsockopt(zmq.EVENTS) & zmq.POLLIN:
            with context():
                kernel.do_one_iteration()

    fd = stream.getsockopt(zmq.FD)
    notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read, kernel.app)
    notifier.activated.connect(process_stream_events) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:eventloops.py

示例11: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def __init__(self, exchange='', addr='ipc:///tmp/feed.ipc', timeout=30):
        """

        :param period: int: Data sampling period
        :param pairs: list: Pair symbols to trade
        :param exchange: str: FeedDaemon exchange to query
        :param addr: str: Client socked address
        :param timeout: int:
        """
        super(DataFeed, self).__init__()

        # Sock objects
        self.context = zmq.Context()
        self.addr = addr
        self.exchange = exchange
        self.timeout = timeout * 1000

        self.sock = self.context.socket(zmq.REQ)
        self.sock.connect(addr)

        self.poll = zmq.Poller()
        self.poll.register(self.sock, zmq.POLLIN) 
开发者ID:naripok,项目名称:cryptotrader,代码行数:24,代码来源:datafeed.py

示例12: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def __init__(self, port, pipeline=100, host='localhost', log_file=None):
        """Create a new ZMQDealer object.
        """
        context = zmq.Context.instance()
        # noinspection PyUnresolvedReferences
        self.socket = context.socket(zmq.DEALER)
        self.socket.hwm = pipeline
        self.socket.connect('tcp://%s:%d' % (host, port))
        self._log_file = log_file
        self.poller = zmq.Poller()
        # noinspection PyUnresolvedReferences
        self.poller.register(self.socket, zmq.POLLIN)

        if self._log_file is not None:
            self._log_file = Path(self._log_file).resolve()
            # If log file directory does not exists, create it
            log_dir: Path = self._log_file.parent
            log_dir.mkdir(parents=True, exist_ok=True)
            # time stamp the file
            now = datetime.now()
            time_stamp = now.strftime('%Y%m%d_%H%M%S%f')
            ext = self._log_file.suffix
            self._log_file = str(log_dir / f'{self._log_file.stem}_{time_stamp}{ext}') 
开发者ID:ucb-art,项目名称:BAG_framework,代码行数:25,代码来源:zmqwrapper.py

示例13: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def __init__(self, port, topic='', timeout=0.01):
        """ Constructs the Listener object with a subscriber port
        over which to listen for messages

        :param port: TCP port to listen on
        :param topic: Topic to listen on
        :param timeout: Timeout in seconds to recheck stop flag
        """
        super().__init__()

        self.port = port
        self.topic = topic
        self.context = zmq.Context()
        log.debug("%s has ZMQ Context: %r" % (self.__class__.__name__, self.context))
        self.subscriber = self.context.socket(zmq.SUB)
        self.subscriber.connect('tcp://localhost:%d' % port)
        self.subscriber.setsockopt(zmq.SUBSCRIBE, topic.encode())
        log.info("%s connected to '%s' topic on tcp://localhost:%d" % (
            self.__class__.__name__, topic, port))

        self.poller = zmq.Poller()
        self.poller.register(self.subscriber, zmq.POLLIN)
        self.timeout = timeout 
开发者ID:ralph-group,项目名称:pymeasure,代码行数:25,代码来源:listeners.py

示例14: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def run(self):
        """ Contents of the infinite loop. """
        # Create zmq sockets
        sockets = SupvisorsZmq(self.supvisors)
        # create poller
        poller = zmq.Poller()
        # register sockets
        poller.register(sockets.internal_subscriber.socket, zmq.POLLIN)
        poller.register(sockets.puller.socket, zmq.POLLIN)
        # poll events forever
        while not self.stopping():
            socks = dict(poller.poll(500))
            # test stop condition again: if Supervisor is stopping,
            # any XML-RPC call would block this thread, and the other
            # because of the join
            if not self.stopping():
                self.check_requests(sockets, socks)
                self.check_events(sockets.internal_subscriber, socks)
        # close resources gracefully
        poller.unregister(sockets.puller.socket)
        poller.unregister(sockets.internal_subscriber.socket)
        sockets.close() 
开发者ID:julien6387,项目名称:supvisors,代码行数:24,代码来源:mainloop.py

示例15: check_events

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import POLLIN [as 别名]
def check_events(self, subscriber, socks):
        """ Forward external Supervisor events to main thread. """
        if subscriber.socket in socks and \
            socks[subscriber.socket] == zmq.POLLIN:
            try:
                message = subscriber.receive()
            except:
                print >> stderr, '[ERROR] failed to get data from subscriber'
            else:
                # The events received are not processed directly in this thread
                # because it would conflict with the processing in the
                # Supervisor thread, as they use the same data.
                # That's why a RemoteCommunicationEvent is used to push the
                # event in the Supervisor thread.
                self.send_remote_comm_event(
                    RemoteCommEvents.SUPVISORS_EVENT,
                    json.dumps(message)) 
开发者ID:julien6387,项目名称:supvisors,代码行数:19,代码来源:mainloop.py


注:本文中的zmq.POLLIN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。