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


Python errno.EAGAIN属性代码示例

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


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

示例1: _receive_device

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _receive_device(self):
        """Receive a single device from the monitor.

        Return the received :class:`Device`, or ``None`` if no device could be
        received.

        """
        while True:
            try:
                device_p = self._libudev.udev_monitor_receive_device(self)
                return Device(self.context, device_p) if device_p else None
            except EnvironmentError as error:
                if error.errno in (errno.EAGAIN, errno.EWOULDBLOCK):
                    # No data available
                    return None
                elif error.errno == errno.EINTR:
                    # Try again if our system call was interrupted
                    continue
                else:
                    raise 
开发者ID:mbusb,项目名称:multibootusb,代码行数:22,代码来源:monitor.py

示例2: _raise_timeout

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _raise_timeout(self, err, url, timeout_value):
        """Is the error actually a timeout? Will raise a ReadTimeout or pass"""

        if isinstance(err, SocketTimeout):
            raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)

        # See the above comment about EAGAIN in Python 3. In Python 2 we have
        # to specifically catch it and throw the timeout error
        if hasattr(err, 'errno') and err.errno in _blocking_errnos:
            raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)

        # Catch possible read timeouts thrown as SSL errors. If not the
        # case, rethrow the original. We need to do this because of:
        # http://bugs.python.org/issue10272
        if 'timed out' in str(err) or 'did not complete (read)' in str(err):  # Python 2.6
            raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:18,代码来源:connectionpool.py

示例3: _flush_unlocked

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _flush_unlocked(self):
        if self.closed:
            raise ValueError("flush of closed file")
        while self._write_buf:
            try:
                n = self.raw.write(self._write_buf)
            except InterruptedError:
                continue
            except BlockingIOError:
                raise RuntimeError("self.raw should implement RawIOBase: it "
                                   "should not raise BlockingIOError")
            if n is None:
                raise BlockingIOError(
                    errno.EAGAIN,
                    "write could not complete without blocking", 0)
            if n > len(self._write_buf) or n < 0:
                raise IOError("write() returned incorrect number of bytes")
            del self._write_buf[:n] 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:_io.py

示例4: _raise_timeout

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _raise_timeout(self, err, url, timeout_value):
        """Is the error actually a timeout? Will raise a ReadTimeout or pass"""

        if isinstance(err, SocketTimeout):
            raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)

        # See the above comment about EAGAIN in Python 3. In Python 2 we have
        # to specifically catch it and throw the timeout error
        if hasattr(err, 'errno') and err.errno in _blocking_errnos:
            raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)

        # Catch possible read timeouts thrown as SSL errors. If not the
        # case, rethrow the original. We need to do this because of:
        # http://bugs.python.org/issue10272
        if 'timed out' in str(err) or 'did not complete (read)' in str(err):  # Python < 2.7.4
            raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:18,代码来源:connectionpool.py

示例5: _send_buffer

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _send_buffer(self, buff, target, send_all=False):
        size = len(buff)
        tosend = size
        already_sent = 0

        while tosend > 0:
            try:
                # i should be able to send a bytearray
                sent = target.send(buff[already_sent:])
                if sent == 0:
                    raise RuntimeError('socket connection broken')

                already_sent += sent
                tosend -= sent

            except socket.error as e:
                # if full buffers then wait for them to drain and try again
                if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
                    if send_all:
                        continue
                    return buff[already_sent:]
                else:
                    raise exception.SocketException(str(e))
        return None 
开发者ID:openstack,项目名称:zun,代码行数:26,代码来源:websocketproxy.py

示例6: _raise_timeout

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _raise_timeout(self, err, url, timeout_value):
        """Is the error actually a timeout? Will raise a ReadTimeout or pass"""

        if isinstance(err, SocketTimeout):
            raise ReadTimeoutError(
                self, url, "Read timed out. (read timeout=%s)" % timeout_value
            )

        # See the above comment about EAGAIN in Python 3. In Python 2 we have
        # to specifically catch it and throw the timeout error
        if hasattr(err, "errno") and err.errno in _blocking_errnos:
            raise ReadTimeoutError(
                self, url, "Read timed out. (read timeout=%s)" % timeout_value
            )

        # Catch possible read timeouts thrown as SSL errors. If not the
        # case, rethrow the original. We need to do this because of:
        # http://bugs.python.org/issue10272
        if "timed out" in str(err) or "did not complete (read)" in str(
            err
        ):  # Python < 2.7.4
            raise ReadTimeoutError(
                self, url, "Read timed out. (read timeout=%s)" % timeout_value
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:26,代码来源:connectionpool.py

示例7: recvfrom

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def recvfrom(self, bufsize, flags=0):
        if self.type != socket.SOCK_DGRAM:
            return _BaseSocket.recvfrom(self, bufsize, flags)
        if not self._proxyconn:
            self.bind(("", 0))
        
        buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
        buf.seek(+2, SEEK_CUR)
        frag = buf.read(1)
        if ord(frag):
            raise NotImplementedError("Received UDP packet fragment")
        fromhost, fromport = self._read_SOCKS5_address(buf)
        
        peerhost, peerport = self.proxy_peername
        filterhost = socket.inet_pton(self.family, peerhost).strip(b"\x00")
        filterhost = filterhost and fromhost != peerhost
        if filterhost or peerport not in (0, fromport):
            raise socket.error(EAGAIN, "Packet filtered")
        
        return (buf.read(), (fromhost, fromport)) 
开发者ID:jmarth,项目名称:plugin.video.kmediatorrent,代码行数:22,代码来源:socks.py

示例8: test_send_command_unreliable_network

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def test_send_command_unreliable_network(self):
        collectd = Mock()

        self.response_chunks = [
            IOError(errno.EAGAIN, ""),
            b"this is\n",
            b"a\n",
            IOError(errno.EINTR, ""),
            b" fake response\n\n",
            None
        ]

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        result = s.send_command("a command")

        self.socket.sendall.assert_called_once_with(b"a command\n")

        self.assertEqual(
            result,
            """this is
a
 fake response"""
        ) 
开发者ID:wglass,项目名称:collectd-haproxy,代码行数:26,代码来源:test_connection.py

示例9: recvfrom

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def recvfrom(self, bufsize, flags=0):
        if self.type != socket.SOCK_DGRAM:
            return _BaseSocket.recvfrom(self, bufsize, flags)
        if not self._proxyconn:
            self.bind(("", 0))

        buf = BytesIO(_BaseSocket.recv(self, bufsize, flags))
        buf.seek(+2, SEEK_CUR)
        frag = buf.read(1)
        if ord(frag):
            raise NotImplementedError("Received UDP packet fragment")
        fromhost, fromport = self._read_SOCKS5_address(buf)

        if self.proxy_peername:
            peerhost, peerport = self.proxy_peername
            if fromhost != peerhost or peerport not in (0, fromport):
                raise socket.error(EAGAIN, "Packet filtered")

        return (buf.read(), (fromhost, fromport)) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:21,代码来源:socks.py

示例10: _sendBuffer

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _sendBuffer(self, buff):
        size = len(buff)
        tosend = size
        already_sent = 0

        while tosend > 0:
            try:
                # i should be able to send a bytearray
                sent = self.client.send(buff[already_sent:])
                if sent == 0:
                    raise RuntimeError('socket connection broken')

                already_sent += sent
                tosend -= sent

            except socket.error as e:
                # if we have full buffers then wait for them to drain and try
                # again
                if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
                    return buff[already_sent:]
                else:
                    raise e

        return None 
开发者ID:ManiacalLabs,项目名称:BiblioPixel,代码行数:26,代码来源:SimpleWebSocketServer.py

示例11: sleep

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def sleep(self):
        """\
        Sleep until PIPE is readable or we timeout.
        A readable PIPE means a signal occurred.
        """
        try:
            ready = select.select([self.PIPE[0]], [], [], 1.0)
            if not ready[0]:
                return
            while os.read(self.PIPE[0], 1):
                pass
        except select.error as e:
            if e.args[0] not in [errno.EAGAIN, errno.EINTR]:
                raise
        except OSError as e:
            if e.errno not in [errno.EAGAIN, errno.EINTR]:
                raise
        except KeyboardInterrupt:
            sys.exit() 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:arbiter.py

示例12: _setup_connection

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _setup_connection(self, dstaddr, timeout=None):
        port = randint(10000, 60000)
        af, socktype, proto, _canonname, _sa = socket.getaddrinfo(dstaddr, port, socket.AF_INET, socket.SOCK_DGRAM)[0]
        s = socket.socket(af, socktype, proto)
        has_bind = 1
        for _i in range(0, 10):
            # We try to bind to a port for 10 tries
            try:
                s.bind((INADDR_ANY, randint(10000, 60000)))
                s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
                has_bind = 1
            except socket.error:
                pass
        if not has_bind:
            raise NetBIOSError, ('Cannot bind to a good UDP port', ERRCLASS_OS, errno.EAGAIN)
        self.__sock = s 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:18,代码来源:nmb.py

示例13: non_polling_read

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def non_polling_read(self, read_length, timeout):
        data = ''
        bytes_left = read_length

        while bytes_left > 0:
            try:
                ready, _, _ = select.select([self._sock.fileno()], [], [], timeout)

                if not ready:
                    raise NetBIOSTimeout

                received = self._sock.recv(bytes_left)
                if len(received) == 0:
                    raise NetBIOSError, ('Error while reading from remote', ERRCLASS_OS, None)

                data = data + received
                bytes_left = read_length - len(data)
            except select.error, ex:
                if ex[0] != errno.EINTR and ex[0] != errno.EAGAIN:
                    raise NetBIOSError, ('Error occurs while reading from remote', ERRCLASS_OS, ex[0]) 
开发者ID:joxeankoret,项目名称:CVE-2017-7494,代码行数:22,代码来源:nmb.py

示例14: _receive

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def _receive(self):
        """Receive any incoming socket data.

            If an error is thrown, handle it and return an empty string.

        :return: data_in
        :rtype: bytes
        """
        data_in = EMPTY_BUFFER
        try:
            if not self.socket:
                raise socket.error('connection/socket error')
            data_in = self._read_from_socket()
        except socket.timeout:
            pass
        except (IOError, OSError) as why:
            if why.args[0] not in (EWOULDBLOCK, EAGAIN):
                self._exceptions.append(AMQPConnectionError(why))
                self._running.clear()
        return data_in 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:22,代码来源:io.py

示例15: read

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EAGAIN [as 别名]
def read(self, size):
        while len(self.buffer) < size:
            self.ensure_connection()

            try:
                packet = self.socket.recv(self.buffer_size)
            except socket.error as error:
                if error.errno in (EDEADLK, EAGAIN, EWOULDBLOCK):
                    gevent.sleep()
                    continue
                six.raise_from(NSQSocketError(*error.args), error)

            if not packet:
                self.close()

            self.buffer += packet

        data = self.buffer[:size]
        self.buffer = self.buffer[size:]

        return data 
开发者ID:wtolson,项目名称:gnsq,代码行数:23,代码来源:stream.py


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