當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。