當前位置: 首頁>>代碼示例>>Python>>正文


Python io.BlockingIOError方法代碼示例

本文整理匯總了Python中io.BlockingIOError方法的典型用法代碼示例。如果您正苦於以下問題:Python io.BlockingIOError方法的具體用法?Python io.BlockingIOError怎麽用?Python io.BlockingIOError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io的用法示例。


在下文中一共展示了io.BlockingIOError方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: recv_raw

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def recv_raw(self, x=MTU):
        try:
            data, address = self.ins.recvfrom(x)
        except io.BlockingIOError:
            return None, None, None
        from scapy.layers.inet import IP
        from scapy.layers.inet6 import IPv6
        if self.ipv6:
            # AF_INET6 does not return the IPv6 header. Let's build it
            # (host, port, flowinfo, scopeid)
            host, _, flowinfo, _ = address
            header = raw(IPv6(src=host,
                              dst=self.host_ip6,
                              fl=flowinfo,
                              nh=self.proto,  # fixed for AF_INET6
                              plen=len(data)))
            return IPv6, header + data, time.time()
        else:
            return IP, data, time.time() 
開發者ID:secdev,項目名稱:scapy,代碼行數:21,代碼來源:native.py

示例2: _read_bytes

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def _read_bytes(fp, size, error_template="ran out of data"):
    """
    Read from file-like object until size bytes are read.
    Raises ValueError if not EOF is encountered before size bytes are read.
    Non-blocking objects only supported if they derive from io objects.

    Required as e.g. ZipExtFile in python 2.6 can return less data than
    requested.
    """
    data = bytes()
    while True:
        # io files (default in python3) return None or raise on
        # would-block, python2 file will truncate, probably nothing can be
        # done about that.  note that regular files can't be non-blocking
        try:
            r = fp.read(size - len(data))
            data += r
            if len(r) == 0 or len(data) == size:
                break
        except io.BlockingIOError:
            pass
    if len(data) != size:
        msg = "EOF: reading %s, expected %d bytes got %d"
        raise ValueError(msg % (error_template, size, len(data)))
    else:
        return data 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:28,代碼來源:format.py

示例3: good_case3

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def good_case3():
    """io.BlockingIOError is defined in C."""
    import io
    raise io.BlockingIOError 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:6,代碼來源:invalid_exceptions_raised.py

示例4: _flush_unlocked

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def _flush_unlocked(self):
        self._checkClosed("flush of closed file")
        while self._write_buf:
            try:
                # ssl sockets only except 'bytes', not bytearrays
                # so perhaps we should conditionally wrap this for perf?
                n = self.raw.write(bytes(self._write_buf))
            except io.BlockingIOError as e:
                n = e.characters_written
            del self._write_buf[:n] 
開發者ID:exiahuang,項目名稱:SalesforceXyTools,代碼行數:12,代碼來源:wsgiserver3.py

示例5: _read_bytes

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def _read_bytes(fp, size, error_template="ran out of data"):
    """Read from file-like object until size bytes are read.

    Raises ValueError if not EOF is encountered before size bytes are read.
    Non-blocking objects only supported if they derive from io objects.

    Required as e.g. ZipExtFile in python 2.6 can return less data than
    requested.

    This function was taken from numpy/lib/format.py in version 1.10.2.

    Parameters
    ----------
    fp: file-like object
    size: int
    error_template: str

    Returns
    -------
    a bytes object
        The data read in bytes.

    """
    data = bytes()
    while True:
        # io files (default in python3) return None or raise on
        # would-block, python2 file will truncate, probably nothing can be
        # done about that.  note that regular files can't be non-blocking
        try:
            r = fp.read(size - len(data))
            data += r
            if len(r) == 0 or len(data) == size:
                break
        except io.BlockingIOError:
            pass
    if len(data) != size:
        msg = "EOF: reading %s, expected %d bytes got %d"
        raise ValueError(msg % (error_template, size, len(data)))
    else:
        return data 
開發者ID:flennerhag,項目名稱:mlens,代碼行數:42,代碼來源:numpy_pickle_utils.py

示例6: lockFile

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def lockFile(f):
    # From http://tilde.town/~cristo/file-locking-in-python.html
    while True:
        try:
            fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
            return
        except (BlockingIOError, IOError) as e:
            # Try again in 1/10th of a second
            time.sleep(0.1) 
開發者ID:terraref,項目名稱:computing-pipeline,代碼行數:11,代碼來源:gantry_scanner_service.py

示例7: _flush_unlocked

# 需要導入模塊: import io [as 別名]
# 或者: from io import BlockingIOError [as 別名]
def _flush_unlocked(self):
        self._checkClosed('flush of closed file')
        while self._write_buf:
            try:
                # ssl sockets only except 'bytes', not bytearrays
                # so perhaps we should conditionally wrap this for perf?
                n = self.raw.write(bytes(self._write_buf))
            except io.BlockingIOError as e:
                n = e.characters_written
            del self._write_buf[:n] 
開發者ID:cherrypy,項目名稱:cheroot,代碼行數:12,代碼來源:makefile.py


注:本文中的io.BlockingIOError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。