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


Python zmq.Poller方法代码示例

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


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

示例1: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def __init__(self, ip_address, port_range):
        """
        Parameters
        ----------

        ip_address: str
           IP address of the client (where Parsl runs)
        port_range: tuple(int, int)
           Port range for the comms between client and interchange

        """
        self.context = zmq.Context()
        self.zmq_socket = self.context.socket(zmq.DEALER)
        self.zmq_socket.set_hwm(0)
        self.port = self.zmq_socket.bind_to_random_port("tcp://{}".format(ip_address),
                                                        min_port=port_range[0],
                                                        max_port=port_range[1])
        self.poller = zmq.Poller()
        self.poller.register(self.zmq_socket, zmq.POLLOUT) 
开发者ID:funcx-faas,项目名称:funcX,代码行数:21,代码来源:zmq_pipes.py

示例2: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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: test_subscribe_method

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def test_subscribe_method(self):
        pub, sub = self.create_bound_pair(zmq.PUB, zmq.SUB)
        sub.subscribe('prefix')
        sub.subscribe = 'c'
        p = zmq.Poller()
        p.register(sub, zmq.POLLIN)
        # wait for subscription handshake
        for i in range(100):
            pub.send(b'canary')
            events = p.poll(250)
            if events:
                break
        self.recv(sub)
        pub.send(b'prefixmessage')
        msg = self.recv(sub)
        self.assertEqual(msg, b'prefixmessage')
        sub.unsubscribe('prefix')
        pub.send(b'prefixmessage')
        events = p.poll(1000)
        self.assertEqual(events, [])
    
    # Travis can't handle how much memory PyPy uses on this test 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_socket.py

示例4: test_timeout

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例5: _DWX_ZMQ_SHUTDOWN_

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def _DWX_ZMQ_SHUTDOWN_(self):
        
        # Set INACTIVE
        self._ACTIVE = False
        
        # Get all threads to shutdown
        if self._MarketData_Thread is not None:
            self._MarketData_Thread.join()
            
        if self._PUSH_Monitor_Thread is not None:
            self._PUSH_Monitor_Thread.join()
            
        if self._PULL_Monitor_Thread is not None:            
            self._PULL_Monitor_Thread.join()
        
        # Unregister sockets from Poller
        self._poller.unregister(self._PULL_SOCKET)
        self._poller.unregister(self._SUB_SOCKET)
        print("\n++ [KERNEL] Sockets unregistered from ZMQ Poller()! ++")
        
        # Terminate context 
        self._ZMQ_CONTEXT.destroy(0)
        print("\n++ [KERNEL] ZeroMQ Context Terminated.. shut down safely complete! :)")
        
    ########################################################################## 
开发者ID:darwinex,项目名称:dwx-zeromq-connector,代码行数:27,代码来源:DWX_ZeroMQ_Connector_v2_0_1_RC8.py

示例6: support_test_send_to_multiple_addresses

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例7: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def __init__(self, socket, io_loop=None):
        self.socket = socket
        self.io_loop = io_loop or IOLoop.instance()
        self.poller = zmq.Poller()
        
        self._send_queue = Queue()
        self._recv_callback = None
        self._send_callback = None
        self._close_callback = None
        self._recv_copy = False
        self._flushed = False
        
        self._state = self.io_loop.ERROR
        self._init_io_state()
        
        # shortcircuit some socket methods
        self.bind = self.socket.bind
        self.bind_to_random_port = self.socket.bind_to_random_port
        self.connect = self.socket.connect
        self.setsockopt = self.socket.setsockopt
        self.getsockopt = self.socket.getsockopt
        self.setsockopt_string = self.socket.setsockopt_string
        self.getsockopt_string = self.socket.getsockopt_string
        self.setsockopt_unicode = self.socket.setsockopt_unicode
        self.getsockopt_unicode = self.socket.getsockopt_unicode 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:zmqstream.py

示例8: _abort_queue

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例9: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例10: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例11: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例12: run

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [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

示例13: check_trigger

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def check_trigger(self):
        """ Wait to receive the json file and reply with the duration of the
        experiment. Then, to the `queue_trigger_params` the received dict,
        so that the `Experiment` can store it with the rest of the data.
        """

        poller = zmq.Poller()
        poller.register(self.zmq_socket, zmq.POLLIN)
        try:
            self.protocol_duration = self.duration_queue.get(timeout=0.0001)
            print(self.protocol_duration)
        except Empty:
            pass
        if poller.poll(10):
            self.scope_config = self.zmq_socket.recv_json()
            self.device_params_queue.put(self.scope_config)
            self.zmq_socket.send_json(self.protocol_duration)
            return True
        else:
            return False 
开发者ID:portugueslab,项目名称:stytra,代码行数:22,代码来源:__init__.py

示例14: _open_zmq_connection

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def _open_zmq_connection(self):
        '''
        Connects to the raspberry via zmq/tcp

        Input:
            None

        Output:
            None
        '''
        
        self.context = zmq.Context(1)
        print("Connecting to Raspberry Pi")
        self.client = self.context.socket(zmq.REQ)
        self.client.connect("tcp://%s:%s"%(self._address,self._port)) # raspi address

        self.poll = zmq.Poller()
        self.poll.register(self.client, zmq.POLLIN) 
开发者ID:qkitgroup,项目名称:qkit,代码行数:20,代码来源:IVVIDIG_main_eth.py

示例15: subscribe

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import Poller [as 别名]
def subscribe(self):
        if self.redis_sub:
            for msg in self.subscribers.listen():
                if msg.get('data', None) is not None:
                    yield msg['data']
        elif self.zmq_sub:
            # Initialize poll set
            poller = zmq.Poller()
            for subscriber in self.subscribers:
                poller.register(subscriber, zmq.POLLIN)

            while True:
                socks = dict(poller.poll())

                for subscriber in self.subscribers:
                    if subscriber in socks:
                        message = subscriber.recv()
                        yield message.split(b' ', 1)[1]
        else:
            raise Exception('No subscribe function defined') 
开发者ID:CIRCL,项目名称:AIL-framework,代码行数:22,代码来源:Helper.py


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