Python fcntl.F_GETFD属性代码示例

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

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

示例1: _set_cloexec

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def _set_cloexec(self):
        """Set the CLOEXEC flag on all open files (except stdin/out/err).
        If self.max_cloexec_files is an integer (the default), then on
        platforms which support it, it represents the max open files setting
        for the operating system. This function will be called just before
        the process is restarted via os.execv() to prevent open files
        from persisting into the new process.
        Set self.max_cloexec_files to 0 to disable this behavior.
        """
        for fd in range(3, self.max_cloexec_files):  # skip stdin/out/err
            try:
                flags = fcntl.fcntl(fd, fcntl.F_GETFD)
            except IOError:
                continue
            fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:wspbus.py


示例2: write_pid_or_exit

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def write_pid_or_exit(self):
        self.pf = open(self.pidfile, 'w+r')
        pf = self.pf
        fd = pf.fileno()
        fcntl.fcntl(fd, fcntl.F_SETFD,
                    fcntl.fcntl(fd, fcntl.F_GETFD, 0)
                    | fcntl.FD_CLOEXEC)
        try:
            pid = os.getpid()
            logger.debug('write pid:' + str(pid))
            pf.truncate(0)
            pf.write(str(pid))
            pf.flush()
        except Exception as e:
            logger.exception('write pid failed.' + repr(e))
            sys.exit(0) 
开发者ID:bsc-s2,项目名称:pykit,代码行数:22,代码来源:daemonize.py


示例3: set_inheritable

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def set_inheritable(fd, inheritable):
    # On py34+ we can use os.set_inheritable but < py34 we must polyfill
    # with fcntl and SetHandleInformation
    if hasattr(os, 'get_inheritable'):
        if os.get_inheritable(fd) != inheritable:
            os.set_inheritable(fd, inheritable)
    elif WIN:
        h = get_handle(fd)
        flags = winapi.HANDLE_FLAG_INHERIT if inheritable else 0
        winapi.SetHandleInformation(h, winapi.HANDLE_FLAG_INHERIT, flags)
    else:
        flags = fcntl.fcntl(fd, fcntl.F_GETFD)
        if inheritable:
            new_flags = flags & ~fcntl.FD_CLOEXEC
        else:
            new_flags = flags | fcntl.FD_CLOEXEC
        if new_flags != flags:
            fcntl.fcntl(fd, fcntl.F_SETFD, new_flags) 
开发者ID:Pylons,项目名称:hupper,代码行数:22,代码来源:ipc.py


示例4: sys_generic_fcntl64

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def sys_generic_fcntl64(jitter, linux_env):
    # Parse arguments
    fd, cmd, arg = jitter.syscall_args_systemv(3)
    log.debug("sys_fcntl(%x, %x, %x)", fd, cmd, arg)
    # Stub
    fdesc = linux_env.file_descriptors[fd]
    if cmd == fcntl.F_GETFL:
        jitter.syscall_ret_systemv(fdesc.flags)
    elif cmd == fcntl.F_SETFL:
        # Ignore flag change
        jitter.syscall_ret_systemv(0)
    elif cmd == fcntl.F_GETFD:
        jitter.syscall_ret_systemv(fdesc.flags)
    elif cmd == fcntl.F_SETFD:
        # Ignore flag change
        jitter.syscall_ret_systemv(0)
    else:
        raise RuntimeError("Not implemented") 
开发者ID:cea-sec,项目名称:miasm,代码行数:21,代码来源:syscall.py


示例5: set_fd_flag

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def set_fd_flag(fd, flag):
    """Set a flag on a file descriptor.
    ``fd`` is the file descriptor or file object, ``flag`` the flag as integer.
    """
    flags = fcntl.fcntl(fd, fcntl.F_GETFD, 0)
    fcntl.fcntl(fd, fcntl.F_SETFD, flags | flag) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:10,代码来源:pipe.py


示例6: _set_cloexec

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def _set_cloexec(fd):
        try:
            flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
        except OSError:
            pass
        else:
            # flags read successfully, modify
            flags |= _fcntl.FD_CLOEXEC
            _fcntl.fcntl(fd, _fcntl.F_SETFD, flags) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:tempfile.py


示例7: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
                 logRequests=True, allow_none=False, encoding=None,
                 bind_and_activate=True, use_builtin_types=False):
        self.logRequests = logRequests
        SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding, use_builtin_types)
        socketserver.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
        # [Bug #1222790] If possible, set close-on-exec flag; if a
        # method spawns a subprocess, the subprocess shouldn't have
        # the listening socket open.
        if fcntl is not None and hasattr(fcntl, 'FD_CLOEXEC'):
            flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
            flags |= fcntl.FD_CLOEXEC
            fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:17,代码来源:server.py


示例8: set_close_exec

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def set_close_exec(fd):
    flags = fcntl.fcntl(fd, fcntl.F_GETFD)
    fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:posix.py


示例9: set_noinherit

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def set_noinherit(sock: socket.socket) -> None:
        """Mark the given socket fd as non-inheritable to child processes"""
        fd = sock.fileno()
        flags = fcntl.fcntl(fd, fcntl.F_GETFD)
        fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) 
开发者ID:irmen,项目名称:Pyro5,代码行数:7,代码来源:socketutil.py


示例10: close_on_exec

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def close_on_exec(fd):
    flags = fcntl.fcntl(fd, fcntl.F_GETFD)
    flags |= fcntl.FD_CLOEXEC
    fcntl.fcntl(fd, fcntl.F_SETFD, flags) 
开发者ID:jpush,项目名称:jbox,代码行数:6,代码来源:util.py


示例11: write_pid_file

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def write_pid_file(pid_file, pid):
    import fcntl
    import stat
    try:
        fd = os.open(pid_file, os.O_RDWR | os.O_CREAT,
                     stat.S_IRUSR | stat.S_IWUSR)
    except OSError as e:
        shell.print_exception(e)
        return -1
    flags = fcntl.fcntl(fd, fcntl.F_GETFD)
    assert flags != -1
    flags |= fcntl.FD_CLOEXEC
    r = fcntl.fcntl(fd, fcntl.F_SETFD, flags)
    assert r != -1
    # There is no platform independent way to implement fcntl(fd, F_SETLK, &fl)
    # via fcntl.fcntl. So use lockf instead
    try:
        fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB, 0, 0, os.SEEK_SET)
    except IOError:
        r = os.read(fd, 32)
        if r:
            logging.error('already started at pid %s' % common.to_str(r))
        else:
            logging.error('already started')
        os.close(fd)
        return -1
    os.ftruncate(fd, 0)
    os.write(fd, common.to_bytes(str(pid)))
    return 0 
开发者ID:ntfreedom,项目名称:neverendshadowsocks,代码行数:32,代码来源:daemon.py


示例12: _set_cloexec_flag

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def _set_cloexec_flag(self, fd):
            try:
                cloexec_flag = fcntl.FD_CLOEXEC
            except AttributeError:
                cloexec_flag = 1
            old = fcntl.fcntl(fd, fcntl.F_GETFD)
            fcntl.fcntl(fd, fcntl.F_SETFD, old | cloexec_flag) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:10,代码来源:subprocess24.py


示例13: _set_cloexec

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def _set_cloexec(fd):
        try:
            flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
        except IOError:
            pass
        else:
            # flags read successfully, modify
            flags |= _fcntl.FD_CLOEXEC
            _fcntl.fcntl(fd, _fcntl.F_SETFD, flags) 
开发者ID:glmcdona,项目名称:meddle,代码行数:11,代码来源:tempfile.py


示例14: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
                 logRequests=True, allow_none=False, encoding=None, bind_and_activate=True):
        self.logRequests = logRequests
        SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
        SocketServer.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
        # [Bug #1222790] If possible, set close-on-exec flag; if a
        # method spawns a subprocess, the subprocess shouldn't have
        # the listening socket open.
        if fcntl is not None and hasattr(fcntl, 'FD_CLOEXEC'):
            flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
            flags |= fcntl.FD_CLOEXEC
            fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags) 
开发者ID:glmcdona,项目名称:meddle,代码行数:16,代码来源:SimpleXMLRPCServer.py


示例15: _set_cloexec_flag

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def _set_cloexec_flag(self, fd, cloexec=True):
            try:
                cloexec_flag = fcntl.FD_CLOEXEC
            except AttributeError:
                cloexec_flag = 1
            old = fcntl.fcntl(fd, fcntl.F_GETFD)
            if cloexec:
                fcntl.fcntl(fd, fcntl.F_SETFD, old | cloexec_flag)
            else:
                fcntl.fcntl(fd, fcntl.F_SETFD, old & ~cloexec_flag) 
开发者ID:glmcdona,项目名称:meddle,代码行数:13,代码来源:subprocess.py


示例16: flags

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def flags(self, *which):
        import fcntl, os
        if which:
            if len(which) > 1:
                raise TypeError, 'Too many arguments'
            which = which[0]
        else: which = '?'
        l_flags = 0
        if 'n' in which: l_flags = l_flags | os.O_NDELAY
        if 'a' in which: l_flags = l_flags | os.O_APPEND
        if 's' in which: l_flags = l_flags | os.O_SYNC
        file = self._file_
        if '=' not in which:
            cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
            if '!' in which: l_flags = cur_fl & ~ l_flags
            else: l_flags = cur_fl | l_flags
        l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)
        if 'c' in which:
            arg = ('!' not in which)    # 0 is don't, 1 is do close on exec
            l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)
        if '?' in which:
            which = ''                  # Return current flags
            l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
            if os.O_APPEND & l_flags: which = which + 'a'
            if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
                which = which + 'c'
            if os.O_NDELAY & l_flags: which = which + 'n'
            if os.O_SYNC & l_flags: which = which + 's'
            return which 
开发者ID:glmcdona,项目名称:meddle,代码行数:38,代码来源:posixfile.py


示例17: set_close_exec

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def set_close_exec(fd: int) -> None:
    flags = fcntl.fcntl(fd, fcntl.F_GETFD)
    fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:5,代码来源:posix.py


示例18: prevent_socket_inheritance

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def prevent_socket_inheritance(sock):
        """Mark the given socket fd as non-inheritable (POSIX)."""
        fd = sock.fileno()
        old_flags = fcntl.fcntl(fd, fcntl.F_GETFD)
        fcntl.fcntl(fd, fcntl.F_SETFD, old_flags | fcntl.FD_CLOEXEC) 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:7,代码来源:wsgiserver3.py


示例19: _set_non_inheritable_non_atomic

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFD [as 别名]
def _set_non_inheritable_non_atomic(fd):
        """Set the close-on-exec flag on the given file descriptor."""
        flags = fcntl(fd, F_GETFD)
        fcntl(fd, F_SETFD, flags | FD_CLOEXEC) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:pool.py



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