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


Python fcntl.F_GETFD屬性代碼示例

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


在下文中一共展示了fcntl.F_GETFD屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


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