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


Python os.pipe2方法代码示例

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


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

示例1: _pipe2_by_pipe

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def _pipe2_by_pipe(flags):
    """A ``pipe2`` implementation using :func:`os.pipe`.

    ``flags`` is an integer providing the flags to ``pipe2``.

    .. warning::

       This implementation is not atomic!

    Return a pair of file descriptors ``(r, w)``.

    """
    fds = os.pipe()
    if flags & os.O_NONBLOCK != 0:
        for fd in fds:
            set_fd_status_flag(fd, os.O_NONBLOCK)
    if flags & O_CLOEXEC != 0:
        for fd in fds:
            set_fd_flag(fd, O_CLOEXEC)
    return fds 
开发者ID:mbusb,项目名称:multibootusb,代码行数:22,代码来源:pipe.py

示例2: test_pipe2

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def test_pipe2(self):
        self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
        self.assertRaises(TypeError, os.pipe2, 0, 0)

        # try calling with flags = 0, like os.pipe()
        r, w = os.pipe2(0)
        os.close(r)
        os.close(w)

        # test flags
        r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
        self.addCleanup(os.close, r)
        self.addCleanup(os.close, w)
        self.assertFalse(os.get_inheritable(r))
        self.assertFalse(os.get_inheritable(w))
        self.assertFalse(os.get_blocking(r))
        self.assertFalse(os.get_blocking(w))
        # try reading from an empty pipe: this should fail, not block
        self.assertRaises(OSError, os.read, r, 1)
        # try a write big enough to fill-up the pipe: this should either
        # fail or perform a partial write, not block
        try:
            os.write(w, b'x' * support.PIPE_MAX_SIZE)
        except OSError:
            pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:27,代码来源:test_posix.py

示例3: test_pipe2

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def test_pipe2(self):
        self.assertRaises(TypeError, os.pipe2, 'DEADBEEF')
        self.assertRaises(TypeError, os.pipe2, 0, 0)

        # try calling with flags = 0, like os.pipe()
        r, w = os.pipe2(0)
        os.close(r)
        os.close(w)

        # test flags
        r, w = os.pipe2(os.O_CLOEXEC|os.O_NONBLOCK)
        self.addCleanup(os.close, r)
        self.addCleanup(os.close, w)
        self.assertFalse(os.get_inheritable(r))
        self.assertFalse(os.get_inheritable(w))
        self.assertTrue(fcntl.fcntl(r, fcntl.F_GETFL) & os.O_NONBLOCK)
        self.assertTrue(fcntl.fcntl(w, fcntl.F_GETFL) & os.O_NONBLOCK)
        # try reading from an empty pipe: this should fail, not block
        self.assertRaises(OSError, os.read, r, 1)
        # try a write big enough to fill-up the pipe: this should either
        # fail or perform a partial write, not block
        try:
            os.write(w, b'x' * support.PIPE_MAX_SIZE)
        except OSError:
            pass 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_posix.py

示例4: _pipe2_ctypes

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def _pipe2_ctypes(libc, flags):
    """A ``pipe2`` implementation using ``pipe2`` from ctypes.

    ``libc`` is a :class:`ctypes.CDLL` object for libc.  ``flags`` is an
    integer providing the flags to ``pipe2``.

    Return a pair of file descriptors ``(r, w)``.

    """
    fds = fd_pair()
    libc.pipe2(fds, flags)
    return fds[0], fds[1] 
开发者ID:mbusb,项目名称:multibootusb,代码行数:14,代码来源:pipe.py

示例5: _get_pipe2_implementation

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def _get_pipe2_implementation():
    """Find the appropriate implementation for ``pipe2``.

Return a function implementing ``pipe2``."""
    if hasattr(os, 'pipe2'):
        return os.pipe2 # pylint: disable=no-member
    else:
        try:
            libc = load_ctypes_library("libc", SIGNATURES, ERROR_CHECKERS)
            return (partial(_pipe2_ctypes, libc)
                    if hasattr(libc, 'pipe2') else
                    _pipe2_by_pipe)
        except ImportError:
            return _pipe2_by_pipe 
开发者ID:mbusb,项目名称:multibootusb,代码行数:16,代码来源:pipe.py

示例6: test_pipe2_c_limits

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def test_pipe2_c_limits(self):
        # Issue 15989
        import _testcapi
        self.assertRaises(OverflowError, os.pipe2, _testcapi.INT_MAX + 1)
        self.assertRaises(OverflowError, os.pipe2, _testcapi.UINT_MAX + 1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_posix.py

示例7: _read_pages2

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def _read_pages2(book, background=False):
    '''Index `book`.
    If `background` is True, yield during long operations.
    If `book` is already loaded, does nothing.
    Upon return `book` will be in state DONE or FAILED.'''
    if book.filename == manual_filename:
        return book
    if book.load_state == book_file.LoadState.DONE:
        return book
    try:
        (r, w) = os.pipe2(os.O_CLOEXEC)
        indexer.trigger_load(book.filename, w)
        buf = None
        if background:
            os.set_blocking(r, False)
            while not buf:
                try:
                    buf = os.read(r, 10)
                except BlockingIOError:
                    await asyncio.sleep(0)
        else:
            os.set_blocking(r, True)
            buf = os.read(r, 10)
        if buf != b'ok':
            raise BookFileError(
                'loading failed: {}'.format(book.filename))
        log.info('loading complete for {}'.format(book.filename))
        bookmarks = book.bookmarks
        if indexer.get_page_count(book.filename) > 1:
            # add an end-of-book bookmark
            bookmarks += (indexer.get_page_count(book.filename) - 1,)
        return book._replace(load_state=book_file.LoadState.DONE,
                             bookmarks=bookmarks,
                             num_pages=indexer.get_page_count(book.filename),
                             indexed=True)
    except Exception:
        log.warning('book loading failed for {}'.format(book.filename))
        return book._replace(load_state=book_file.LoadState.FAILED) 
开发者ID:Bristol-Braille,项目名称:canute-ui,代码行数:40,代码来源:handlers.py

示例8: pipe2

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def pipe2():
    try:
        read_fd, write_fd = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC)
    except AttributeError:
        import fcntl
        read_fd, write_fd = os.pipe()
        for fd in (read_fd, write_fd):
            flag = fcntl.fcntl(fd, fcntl.F_GETFD)
            fcntl.fcntl(fd, fcntl.F_SETFD, flag | fcntl.FD_CLOEXEC)
            flag = fcntl.fcntl(fd, fcntl.F_GETFL)
            fcntl.fcntl(fd, fcntl.F_SETFL, flag | os.O_NONBLOCK)
    return read_fd, write_fd 
开发者ID:kovidgoyal,项目名称:vise,代码行数:14,代码来源:utils.py

示例9: pipe_no_wait

# 需要导入模块: import os [as 别名]
# 或者: from os import pipe2 [as 别名]
def pipe_no_wait():
    """ Generate a non-block pipe used to fetch the STDERR of ffmpeg.
    """

    if platform == "linux" or platform == "linux2" or platform == "darwin" or platform.startswith("openbsd"):
        import fcntl
        import os

        pipe_rd = 0
        pipe_wd = 0

        if hasattr(os, "pipe2"):
            pipe_rd, pipe_wd = os.pipe2(os.O_NONBLOCK)
        else:
            pipe_rd, pipe_wd = os.pipe()

            try:
                fl = fcntl.fcntl(pipe_rd, fcntl.F_GETFL)
                fcntl.fcntl(pipe_rd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
            except:
                print(sys.exc_info()[1])
                return None, None
        return pipe_rd, pipe_wd

    elif platform == "win32":
        # https://stackoverflow.com/questions/34504970/non-blocking-read-on-os-pipe-on-windows
        import msvcrt
        import os

        from ctypes import windll, byref, wintypes, WinError, POINTER
        from ctypes.wintypes import HANDLE, DWORD, BOOL

        pipe_rd, pipe_wd = os.pipe()

        LPDWORD = POINTER(DWORD)
        PIPE_NOWAIT = wintypes.DWORD(0x00000001)
        ERROR_NO_DATA = 232

        SetNamedPipeHandleState = windll.kernel32.SetNamedPipeHandleState
        SetNamedPipeHandleState.argtypes = [HANDLE, LPDWORD, LPDWORD, LPDWORD]
        SetNamedPipeHandleState.restype = BOOL

        h = msvcrt.get_osfhandle(pipe_rd)

        res = windll.kernel32.SetNamedPipeHandleState(h, byref(PIPE_NOWAIT), None, None)
        if res == 0:
            print(WinError())
            return None, None
        return pipe_rd, pipe_wd 
开发者ID:azlux,项目名称:botamusique,代码行数:51,代码来源:util.py


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