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


Python fcntl.F_GETFL属性代码示例

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


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

示例1: read_char_no_blocking

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def read_char_no_blocking():
    ''' Read a character in nonblocking mode, if no characters are present in the buffer, return an empty string '''
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    old_flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    try:
        tty.setraw(fd, termios.TCSADRAIN)
        fcntl.fcntl(fd, fcntl.F_SETFL, old_flags | os.O_NONBLOCK)
        return sys.stdin.read(1)
    except IOError as e:
        ErrorNumber = e[0]
        # IOError with ErrorNumber 11(35 in Mac)  is thrown when there is nothing to read(Resource temporarily unavailable)
        if (sys.platform.startswith("linux") and ErrorNumber != 11) or (sys.platform == "darwin" and ErrorNumber != 35):
            raise
        return ""
    finally:
        fcntl.fcntl(fd, fcntl.F_SETFL, old_flags)
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 
开发者ID:pindexis,项目名称:marker,代码行数:20,代码来源:readchar.py

示例2: train

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def train(self):
        i=0
        if(self.args.ipython):
            import fcntl
            fd = sys.stdin.fileno()
            fl = fcntl.fcntl(fd, fcntl.F_GETFL)
            fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        while((i < self.total_steps or self.total_steps == -1) and not self.gan.destroy):
            i+=1
            start_time = time.time()
            self.step()
            GlobalViewer.tick()

            if (self.args.save_every != None and
                self.args.save_every != -1 and
                self.args.save_every > 0 and
                i % self.args.save_every == 0):
                print(" |= Saving network")
                self.gan.save(self.save_file)
            if self.args.ipython:
                self.check_stdin()
            end_time = time.time() 
开发者ID:HyperGAN,项目名称:HyperGAN,代码行数:25,代码来源:cli.py

示例3: blocking

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def blocking(self, port, mode=False):
        """
        Set port function mode blocking/nonblocking

        :param port: port to set mode
        :param mode: False to set nonblock mode, True for block mode
        """
        fd = self._open([port])[0]

        try:
            fl = fcntl.fcntl(fd, fcntl.F_GETFL)
            if not mode:
                fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
            else:
                fcntl.fcntl(fd, fcntl.F_SETFL, fl & ~os.O_NONBLOCK)

        except Exception as inst:
            print("FAIL: Setting (non)blocking mode: " + str(inst))
            return

        if mode:
            print("PASS: set to blocking mode")
        else:
            print("PASS: set to nonblocking mode") 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:26,代码来源:virtio_console_guest.py

示例4: set_blocking

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def set_blocking(fd, blocking=True):
    """
    Set the given file-descriptor blocking or non-blocking.

    Returns the original blocking status.
    """

    old_flag = fcntl.fcntl(fd, fcntl.F_GETFL)

    if blocking:
        new_flag = old_flag & ~ os.O_NONBLOCK
    else:
        new_flag = old_flag | os.O_NONBLOCK

    fcntl.fcntl(fd, fcntl.F_SETFL, new_flag)

    return not bool(old_flag & os.O_NONBLOCK) 
开发者ID:QData,项目名称:deepWordBug,代码行数:19,代码来源:io.py

示例5: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def __init__(self, pScene):
        self.pScene = pScene
        #self.infile_path = "/dev/input/event" + (sys.argv[1] if len(sys.argv) > 1 else "0")
        self.infile_path = "/dev/input/event0"
        self.FORMAT = 'llHHI'
        self.EVENT_SIZE = struct.calcsize(self.FORMAT)
        self.lastPtX = 0
        self.lastPtY = 0
        self.rateX = float(480) / 3900
        self.rateY = float(320) / 3900
        self.sep = 0
        #print str(rateX)
        #print str(rateY)
        self.in_file = open(self.infile_path, "rb")
        flag = fcntl.fcntl(self.in_file, fcntl.F_GETFL)
        fcntl.fcntl(self.in_file, fcntl.F_SETFL, os.O_NONBLOCK) 
开发者ID:KONAMI,项目名称:EM-uNetPi,代码行数:18,代码来源:TouchManager.py

示例6: set_nonblock

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def set_nonblock(self, set_flag=True):
        """Set the non blocking flag on the socket"""

        # Get the current flags
        if self.fd_flags is None:
            try:
                self.fd_flags = fcntl.fcntl(self.ins, fcntl.F_GETFL)
            except IOError:
                warning("Cannot get flags on this file descriptor !")
                return

        # Set the non blocking flag
        if set_flag:
            new_fd_flags = self.fd_flags | os.O_NONBLOCK
        else:
            new_fd_flags = self.fd_flags & ~os.O_NONBLOCK

        try:
            fcntl.fcntl(self.ins, fcntl.F_SETFL, new_fd_flags)
            self.fd_flags = new_fd_flags
        except Exception:
            warning("Can't set flags on this file descriptor !") 
开发者ID:secdev,项目名称:scapy,代码行数:24,代码来源:supersocket.py

示例7: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def __init__(self, command):
        """
        Creates an interactive process to interact with out of a command

        :param str command: the command to be executed
        """

        from fcntl import fcntl, F_GETFL, F_SETFL
        from subprocess import Popen, PIPE
        import os

        self._command = command
        self._executable = command.split(" ", 1)[0]

        _Log.debug("Starting the interactive process: {}".format(command))

        self._process = Popen(command, shell=True, stdout=PIPE, stdin=PIPE,
            stderr=PIPE)
        fcntl(self._process.stdin, F_SETFL,
            fcntl(self._process.stdin, F_GETFL) | os.O_NONBLOCK)
        fcntl(self._process.stdout, F_SETFL,
            fcntl(self._process.stdout, F_GETFL) | os.O_NONBLOCK)
        fcntl(self._process.stderr, F_SETFL,
            fcntl(self._process.stderr, F_GETFL) | os.O_NONBLOCK) 
开发者ID:nettitude,项目名称:scrounger,代码行数:26,代码来源:general.py

示例8: set_fd_status_flag

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def set_fd_status_flag(fd, flag):
    """Set a status flag on a file descriptor.

    ``fd`` is the file descriptor or file object, ``flag`` the flag as integer.

    """
    flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0)
    fcntl.fcntl(fd, fcntl.F_SETFL, flags | flag) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:10,代码来源:pipe.py

示例9: SetFileNonBlocking

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def SetFileNonBlocking(f, non_blocking=True):
  """Set non-blocking flag on a file object.

  Args:
    f: file
    non_blocking: bool, default True, non-blocking mode or not
  """
  flags = fcntl.fcntl(f.fileno(), fcntl.F_GETFL)
  if bool(flags & os.O_NONBLOCK) != non_blocking:
    flags ^= os.O_NONBLOCK
  fcntl.fcntl(f.fileno(), fcntl.F_SETFL, flags) 
开发者ID:google,项目名称:macops,代码行数:13,代码来源:gmacpyutil.py

示例10: _set_nonblocking

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

示例11: _set_nonblocking

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def _set_nonblocking(self, fd):
        flags = fcntl.fcntl(fd, fcntl.F_GETFL)
        fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:5,代码来源:twisted_test.py

示例12: activate

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def activate(self):
        """Set up signal handlers.

        On Windows this uses a QTimer to periodically hand control over to
        Python so it can handle signals.

        On Unix, it uses a QSocketNotifier with os.set_wakeup_fd to get
        notified.
        """
        self._orig_handlers[signal.SIGINT] = signal.signal(
            signal.SIGINT, self.interrupt)
        self._orig_handlers[signal.SIGTERM] = signal.signal(
            signal.SIGTERM, self.interrupt)

        if utils.is_posix and hasattr(signal, 'set_wakeup_fd'):
            # pylint: disable=import-error,no-member,useless-suppression
            import fcntl
            read_fd, write_fd = os.pipe()
            for fd in [read_fd, write_fd]:
                flags = fcntl.fcntl(fd, fcntl.F_GETFL)
                fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
            self._notifier = QSocketNotifier(typing.cast(sip.voidptr, read_fd),
                                             QSocketNotifier.Read,
                                             self)
            self._notifier.activated.connect(  # type: ignore[attr-defined]
                self.handle_signal_wakeup)
            self._orig_wakeup_fd = signal.set_wakeup_fd(write_fd)
            # pylint: enable=import-error,no-member,useless-suppression
        else:
            self._timer.start(1000)
            self._timer.timeout.connect(lambda: None)
        self._activated = True 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:34,代码来源:crashsignal.py

示例13: set_binary_mode

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def set_binary_mode(f):
            try:
                fileno = f.fileno()
            except Exception:
                pass
            else:
                flags = fcntl.fcntl(fileno, fcntl.F_GETFL)
                fcntl.fcntl(fileno, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)
            return f 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:_compat.py

示例14: set_non_blocking

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def set_non_blocking(fd):
    flags = fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK
    fcntl.fcntl(fd, fcntl.F_SETFL, flags) 
开发者ID:jpush,项目名称:jbox,代码行数:5,代码来源:util.py

示例15: __init__

# 需要导入模块: import fcntl [as 别名]
# 或者: from fcntl import F_GETFL [as 别名]
def __init__(self, height):
        super(Terminal, self).__init__(height, line_wrap=True, parser=AnsiTerminalParser())

        #Key definitions
        self._map = {}
        for k, v in [
            (Screen.KEY_LEFT, "kcub1"),
            (Screen.KEY_RIGHT, "kcuf1"),
            (Screen.KEY_UP, "kcuu1"),
            (Screen.KEY_DOWN, "kcud1"),
            (Screen.KEY_HOME, "khome"),
            (Screen.KEY_END, "kend"),
            (Screen.KEY_BACK, "kbs"),
        ]:
            self._map[k] = curses.tigetstr(v)
        self._map[Screen.KEY_TAB] = "\t".encode()

        # Open a pseudo TTY to control the interactive session.  Make it non-blocking.
        self._master, slave = pty.openpty()
        fl = fcntl.fcntl(self._master, fcntl.F_GETFL)
        fcntl.fcntl(self._master, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        # Start the shell and thread to pull data from it.
        self._shell = subprocess.Popen(["bash", "-i"], preexec_fn=os.setsid, stdin=slave, stdout=slave, stderr=slave)
        self._lock = threading.Lock()
        self._thread = threading.Thread(target=self._background)
        self._thread.daemon = True
        self._thread.start() 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:30,代码来源:terminal.py


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