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


Python zmq.EAGAIN属性代码示例

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


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

示例1: _check_rc

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def _check_rc(rc, errno=None):
    """internal utility for checking zmq return condition
    
    and raising the appropriate Exception class
    """
    if rc == -1:
        if errno is None:
            from zmq.backend import zmq_errno
            errno = zmq_errno()
        from zmq import EAGAIN, ETERM
        if errno == EINTR:
            raise InterruptedSystemCall(errno)
        elif errno == EAGAIN:
            raise Again(errno)
        elif errno == ETERM:
            raise ContextTerminated(errno)
        else:
            raise ZMQError(errno) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:error.py

示例2: _handle_recv

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def _handle_recv(self):
        """Handle a recv event."""
        if self._flushed:
            return
        try:
            msg = self.socket.recv_multipart(zmq.NOBLOCK, copy=self._recv_copy)
        except zmq.ZMQError as e:
            if e.errno == zmq.EAGAIN:
                # state changed since poll event
                pass
            else:
                raise
        else:
            if self._recv_callback:
                callback = self._recv_callback
                self._run_callback(callback, msg) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:zmqstream.py

示例3: test_root_topic

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def test_root_topic(self):
        logger, handler, sub = self.connect_handler()
        handler.socket.bind(self.iface)
        sub2 = sub.context.socket(zmq.SUB)
        self.sockets.append(sub2)
        sub2.connect(self.iface)
        sub2.setsockopt(zmq.SUBSCRIBE, b'')
        handler.root_topic = b'twoonly'
        msg1 = 'ignored'
        logger.info(msg1)
        self.assertRaisesErrno(zmq.EAGAIN, sub.recv, zmq.NOBLOCK)
        topic,msg2 = sub2.recv_multipart()
        self.assertEqual(topic, b'twoonly.INFO')
        self.assertEqual(msg2, b(msg1)+b'\n')
        
        logger.removeHandler(handler) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_log.py

示例4: poll_command_request

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def poll_command_request(self):
        """If the command RPC socket has an incoming request,
        separate it into its action and its params and put it
        on the command request queue.
        """
        try:
            message = self.rpc.recv(zmq.NOBLOCK)
        except zmq.ZMQError as exc:
            if exc.errno == zmq.EAGAIN:
                return
            else:
                raise

        _logger.debug("Received command %s", message)
        segments = _unpack(message)
        action, params = segments[0], segments[1:]
        _logger.debug("Adding %s, %s to the request queue", action, params)
        self._command = _Command(action, params) 
开发者ID:tjguk,项目名称:networkzero,代码行数:20,代码来源:discovery.py

示例5: get_command

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def get_command(self):
        """Attempt to return a unicode object from the command socket
        
        If no message is available without blocking (as opposed to a blank 
        message), return None
        """
        try:
            message_bytes = self.socket.recv(zmq.NOBLOCK)
            log.debug("Received message: %r", message_bytes)
        except zmq.ZMQError as exc:
            if exc.errno == zmq.EAGAIN:
                return None
            else:
                raise
        else:
            return message_bytes.decode(config.CODEC) 
开发者ID:tjguk,项目名称:networkzero,代码行数:18,代码来源:robot.py

示例6: _check_rc

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def _check_rc(rc, errno=None):
    """internal utility for checking zmq return condition
    
    and raising the appropriate Exception class
    """
    from zmq.backend import zmq_errno
    from errno import EINTR
    from zmq import EAGAIN, ETERM
    if rc < 0:
        if errno is None:
            errno = zmq_errno()
        if errno == EAGAIN:
            raise Again(errno)
        elif errno == ETERM:
            raise ContextTerminated(errno)
        else:
            raise ZMQError(errno) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:error.py

示例7: _handle_recv

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def _handle_recv(self):
        """Handle a recv event."""
        if self._flushed:
            return
        try:
            msg = self.socket.recv_multipart(zmq.NOBLOCK, copy=self._recv_copy)
        except zmq.ZMQError as e:
            if e.errno == zmq.EAGAIN:
                # state changed since poll event
                pass
            else:
                gen_log.error("RECV Error: %s"%zmq.strerror(e.errno))
        else:
            if self._recv_callback:
                callback = self._recv_callback
                # self._recv_callback = None
                self._run_callback(callback, msg)
                
        # self.update_state() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:21,代码来源:zmqstream.py

示例8: causal_put

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def causal_put(self, key, mk_causal_value, client_id):
        request, tuples = self._prepare_causal_data_request(client_id, key,
                                                            MULTI)

        # We can assume this is tuples[0] because we only support one put
        # operation at a time.
        tuples[0].payload, _ = self._serialize(mk_causal_value)

        request.response_address = self.put_response_address
        self.put_request_socket.send(request.SerializeToString())

        # If we get a response from the causal cache in this case, it is
        # guaranteed to succeed, so we don't need to inspect the response
        # message. The only failure case is if the request times out.
        try:
            self.put_response_socket.recv()
        except zmq.ZMQError as e:
            if e.errno == zmq.EAGAIN:
                logging.error("Request for %s timed out!" % (str(key)))
            else:
                logging.error("Unexpected ZMQ error: %s." % (str(e)))

            return False
        else:
            return True 
开发者ID:hydro-project,项目名称:cloudburst,代码行数:27,代码来源:anna_ipc_client.py

示例9: get_ip_set

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def get_ip_set(management_request_socket, exec_threads=True):
    # we can send an empty request because the response is always the same
    management_request_socket.send(b'')

    try:
        ips = StringSet()
        ips.ParseFromString(management_request_socket.recv())
        result = set()

        if exec_threads:
            for ip in ips.keys:
                for i in range(NUM_EXEC_THREADS):
                    result.add((ip, i))

            return result
        else:
            return set(ips.keys)
    except zmq.ZMQError as e:
        if e.errno == zmq.EAGAIN:
            return None
        else:
            raise e 
开发者ID:hydro-project,项目名称:cloudburst,代码行数:24,代码来源:utils.py

示例10: recv

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def recv(self):
        res = []
        while True:
            try:
                # We pass in zmq.NOBLOCK here so that we only check for
                # messages that have already been received.
                msg = self.recv_inbox_socket.recv_pyobj(zmq.NOBLOCK)
                res.append(msg)
            except zmq.ZMQError as e:
                # ZMQ will throw an EAGAIN error with a timeout if there are no
                # pending messages. If that's the case, that means that there
                # are no more messages to be received.
                if e.errno == zmq.EAGAIN:
                    break
                else:
                    raise e

        return res 
开发者ID:hydro-project,项目名称:cloudburst,代码行数:20,代码来源:user_library.py

示例11: put

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def put(self, message, max_timeout=1000):
        """ This function needs to be fast at the same time aware of the possibility of
        ZMQ pipes overflowing.

        The timeout increases slowly if contention is detected on ZMQ pipes.
        We could set copy=False and get slightly better latency but this results
        in ZMQ sockets reaching a broken state once there are ~10k tasks in flight.
        This issue can be magnified if each the serialized buffer itself is larger.

        Parameters
        ----------

        message : py object
             Python object to send
        max_timeout : int
             Max timeout in milliseconds that we will wait for before raising an exception

        Raises
        ------

        zmq.EAGAIN if the send failed.

        """
        timeout_ms = 0
        current_wait = 0
        logger.info("Putting task into queue")
        while current_wait < max_timeout:
            socks = dict(self.poller.poll(timeout=timeout_ms))
            if self.zmq_socket in socks and socks[self.zmq_socket] == zmq.POLLOUT:
                # The copy option adds latency but reduces the risk of ZMQ overflow
                self.zmq_socket.send_pyobj(message, copy=True)
                return
            else:
                timeout_ms += 1
                logger.debug("Not sending due to full zmq pipe, timeout: {} ms".format(timeout_ms))
            current_wait += timeout_ms

        # Send has failed.
        logger.debug("Remote side has been unresponsive for {}".format(current_wait))
        raise zmq.error.Again 
开发者ID:funcx-faas,项目名称:funcX,代码行数:42,代码来源:zmq_pipes.py

示例12: __init__

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def __init__(self, errno='ignored', msg='ignored'):
        from zmq import EAGAIN
        super(Again, self).__init__(EAGAIN) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:error.py

示例13: test_again

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def test_again(self):
        s = self.context.socket(zmq.REP)
        self.assertRaises(Again, s.recv, zmq.NOBLOCK)
        self.assertRaisesErrno(zmq.EAGAIN, s.recv, zmq.NOBLOCK)
        s.close() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_error.py

示例14: assertRaisesErrno

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def assertRaisesErrno(self, errno, func, *args, **kwargs):
        if errno == zmq.EAGAIN:
            raise SkipTest("Skipping because we're green.")
        try:
            func(*args, **kwargs)
        except zmq.ZMQError:
            e = sys.exc_info()[1]
            self.assertEqual(e.errno, errno, "wrong error raised, expected '%s' \
got '%s'" % (zmq.ZMQError(errno), zmq.ZMQError(e.errno)))
        else:
            self.fail("Function did not raise any error") 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:__init__.py

示例15: test_topic

# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import EAGAIN [as 别名]
def test_topic(self):
        s1, s2 = self.create_bound_pair(zmq.PUB, zmq.SUB)
        s2.setsockopt(zmq.SUBSCRIBE, b'x')
        time.sleep(0.1)
        msg1 = b'message'
        s1.send(msg1)
        self.assertRaisesErrno(zmq.EAGAIN, s2.recv, zmq.NOBLOCK)
        msg1 = b'xmessage'
        s1.send(msg1)
        msg2 = s2.recv()
        self.assertEqual(msg1, msg2) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_pubsub.py


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