• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python stdin.fileno函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sys.stdin.fileno函数的典型用法代码示例。如果您正苦于以下问题:Python fileno函数的具体用法?Python fileno怎么用?Python fileno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: myinput

def myinput(timeout=0):
  ESCSEQ = b'\x1b['
  tty.setraw(stdin.fileno())
  #stdout = os.fdopen(stdin.fileno(), 'wb', 0)
  special = False
  while True:
    rlist, wlist, xlist = select([stdin], [], [], 0)
    ch = os.read(stdin.fileno(), 1)
    ch = ch.decode()
    if ch == '\x1b':
      if special:
        yield ESC
      else:
        special = True
    elif ch == '[':
      if not special:
        yield ch
    else:
      if special:
        special = False
        if   ch == 'A': yield UP
        elif ch == 'B': yield DOWN
        elif ch == 'C': yield RIGHT
        elif ch == 'D': yield LEFT
      else:
        yield ch
开发者ID:kopchik,项目名称:perforator,代码行数:26,代码来源:inpt_test.py


示例2: run_client

def run_client():
    ctx = zmq.Context()
    sub = ctx.socket(zmq.SUB)
    sub.connect('tcp://localhost:4455')
    sub.setsockopt(zmq.SUBSCRIBE, "")

    push = ctx.socket(zmq.PUSH)
    push.connect('tcp://localhost:4456')

    plr = zmq.Poller()
    plr.register(stdin.fileno(), zmq.POLLIN)
    plr.register(sub, zmq.POLLIN)

    while True:
        try:
            fds = dict(plr.poll())
        except KeyboardInterrupt:
            print "\nClosing gracefully..."
            return

        if stdin.fileno() in fds:
            line = stdin.readline()[:-1] # trim newline char
            push.send(line)

        if sub in fds:
            msg = sub.recv()
            print "Got message: %r" % (msg,)
开发者ID:mcdd,项目名称:zmqchat,代码行数:27,代码来源:chatclient.py


示例3: getchar

def getchar():
    fd = stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(stdin.fileno())
        ch = stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch
开发者ID:defaultxr,项目名称:taptempo,代码行数:9,代码来源:taptempo.py


示例4: cbreak

def cbreak():
  if hasattr(stdin, "fileno") and os.isatty(stdin.fileno()):
    old_attrs = termios.tcgetattr(stdin)
    tty.setcbreak(stdin)
    tty.setraw(stdin)
  try:
    yield
  finally:
    if hasattr(stdin, "fileno") and os.isatty(stdin.fileno()):
      termios.tcsetattr(stdin, termios.TCSADRAIN, old_attrs)
开发者ID:peterjanetka,项目名称:YunBridge,代码行数:10,代码来源:packet.py


示例5: init

def init():
    flags = fcntl.fcntl(stdin.fileno(), fcntl.F_GETFL)
    if flags == flags | os.O_NONBLOCK:
        return
    else:
        rv = fcntl.fcntl(stdin.fileno(), fcntl.F_SETFL, flags | os.O_NONBLOCK)
        if rv == 0:
            print "ok"
        else:
            print "broken"
开发者ID:jbweber,项目名称:bgplab,代码行数:10,代码来源:test.py


示例6: stdin_handler

def stdin_handler():
    fcntl.fcntl(stdin, fcntl.F_SETFL, os.O_NONBLOCK)
    while True:
        wait_read(stdin.fileno())
        cmd = stdin.readline().strip().lower()
        if cmd == 'quit':
            exit(0)
开发者ID:theonewolf,项目名称:Quantavia,代码行数:7,代码来源:quantavia.py


示例7: connect

def connect(host, handshake):
    s = socket()
    s.connect((host, PORT))
    s.send(handshake)
    print('Connected, press ^C or ^D to terminate the connection.')
    try:
        fd = stdin.fileno()
        old_settings = tcgetattr(fd)
        setraw(fd)
        while True:
            r, _, _ = select([stdin, s], [], [])
            for ready in r:
                if ready is s:
                    r = s.recv(4096)
                    if not r:
                        print('Connection closed by remote peer', file=stderr)
                        return
                    stdout.write(r)
                    stdout.flush()
                elif ready is stdin:
                    r = stdin.read(1)
                    if not r or chr(3) in r or chr(4) in r:
                        s.shutdown(SHUT_RDWR)
                        return
                    s.send(r)
    finally:
        tcsetattr(fd, TCSADRAIN, old_settings)
开发者ID:hpssjellis,项目名称:spares,代码行数:27,代码来源:spares.py


示例8: main

def main():
	global parser
	global verbose
	global pretty

	parser.add_argument("-v", "--verbose", dest="verbose", action='store_true',
						help="verbose output")
	parser.add_argument("-p", "--pretty", dest="pretty", action='store_true',
						help="pretty output. requires PTable module")
	parser.add_argument("-S", "--section", dest="section", default=None,
					help="""\
define a section in the following format;
	NAME SIZE SYM1 SYM2 SYM3
use SIZE as zero to skip size usage calculation
\
					""", action='append')

	options = parser.parse_args()

	is_pipe = not isatty(stdin.fileno())

	if not is_pipe or not options.section:
		usage()
		quit(1)

	if options.verbose:
		verbose = True

	if options.pretty:
		pretty = True

	sections = parse_arg_sections(options.section)
	sizes = parse(sections)

	output(sizes)
开发者ID:thewisenerd,项目名称:dotfiles,代码行数:35,代码来源:size-prettify.py


示例9: _daemonize

 def _daemonize(self):
     try:
         pid = os.fork()
         if pid > 0:
             exit()
     except OSError as e:
         error(_('Error entering daemon mode: %s') % e.strerror)
         exit()
     os.chdir('/')
     os.setsid()
     os.umask(0)
     stdout.flush()
     stderr.flush()
     si = open(os.devnull, 'r')
     so = open(os.devnull, 'a+')
     se = open(os.devnull, 'a+')
     os.dup2(si.fileno(), stdin.fileno())
     os.dup2(so.fileno(), stdout.fileno())
     os.dup2(se.fileno(), stderr.fileno())
     on_exit(self._quit)
     old_log = getLogger()
     if old_log.handlers:
         for handler in old_log.handlers:
             old_log.removeHandler(handler)
     log(filename=self.logfile, level=self.loglevel,
         format='%(asctime)s %(levelname)-8s %(message)s')
     self._set_pid()
开发者ID:debomatic,项目名称:debomatic,代码行数:27,代码来源:process.py


示例10: pos

 def pos(stream=stdout):
     '''Get cursor position.'''
     
     # Save term settings
     fd = stdin.fileno()
     prev = termios.tcgetattr(fd)
     
     stream.write("\033[6n")
     
     resp = ""
     ch = ''
     
     # Immitate getch() until 'R' (end of tty response, e.g. \033[1;1R)
     try:
         tty.setraw(fd)
         while ch!='R':
             ch = stdin.read(1)
             resp += ch
     
     finally:
         # Reset term mode
         termios.tcsetattr(fd, termios.TCSADRAIN, prev)
     
     try:
         # First two chars in response are \033 and [, last is R
         return [int(c) for c in resp[2:-1].split(';')]
     except:
         # In case of failure
         return [-1, -1]
开发者ID:ilvrvltn,项目名称:ncaa,代码行数:29,代码来源:terminal.py


示例11: get_terminal_size_posix

def get_terminal_size_posix():
    def ioctl_GWINSZ(fd):
        try:
            import fcntl
            import termios
            cr = struct.unpack('hh',
                               fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
            return cr
        except:
            pass
    cr = ioctl_GWINSZ(stdin.fileno()) or \
         ioctl_GWINSZ(stdout.fileno()) or \
         ioctl_GWINSZ(stderr.fileno())
    if not cr:
        try:
            with os.open(os.ctermid(), os.O_RDONLY) as fd:
            	cr = ioctl_GWINSZ(fd)
        except:
            pass
    if not cr:
        try:
            cr = (os.environ['LINES'], os.environ['COLUMNS'])
        except:
            pass
    if not cr:
        raise TerminalError('cannot determine terminal size from POSIX')
    return int(cr[1]), int(cr[0])
开发者ID:edrevo,项目名称:fiware-cosmos-platform,代码行数:27,代码来源:terminal.py


示例12: daemonize

   def daemonize(self):
      """
      Forks the process(es) from the controlling terminal
      and redirects I/O streams for logging.
      """

      self.fork()

      chdir(getcwd())
      setsid()
      umask(0)
  
      self.fork()
      stdout.flush()
      stderr.flush()

      si= file(self.stdin, 'w+')
      so= file(self.stdout, 'a+')
      se= file(self.stderr, 'a+', 0)

      dup2(si.fileno(), stdin.fileno())
      dup2(so.fileno(), stdout.fileno())
      dup2(se.fileno(), stderr.fileno())

      register(self.del_pid)
      self.set_pid()
开发者ID:richardjmarini,项目名称:Impetus,代码行数:26,代码来源:impetus.py


示例13: enableEchoMode

def enableEchoMode():
    fd = stdin.fileno()
    state = tcgetattr(fd)
    if state[TERMIO_LFLAGS] & ECHO:
        return False
    state[TERMIO_LFLAGS] = state[TERMIO_LFLAGS] | ECHO
    tcsetattr(fd, TCSADRAIN, state)
    return True
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:8,代码来源:terminal.py


示例14: clear

def clear(): # LIMPANDO A TELA
	import curses
	import termios
	from sys import stdin
	fd = stdin.fileno()
	scr = termios.tcgetattr(fd)
	scrn = curses.initscr()
	scrn.clear()
	termios.tcsetattr(fd, termios.TCSADRAIN, scr)
开发者ID:FernandoNesi,项目名称:SAS-Trabalhos,代码行数:9,代码来源:main.py


示例15: daemonize

    def daemonize(self):
        try:
            pid = fork()
            if pid > 0:
                # exit first parent
                _exit(0)
        except OSError as e:
            stderr.write(
                "fork #1 failed: {0:d} ({1:s})\n".format(
                    e.errno, str(e)
                )
            )

            raise SystemExit(1)

        # decouple from parent environment
        chdir(self.path)
        setsid()
        umask(0)

        # do second fork
        try:
            pid = fork()
            if pid > 0:
                # exit from second parent
                _exit(0)
        except OSError as e:
            stderr.write(
                "fork #2 failed: {0:d} ({1:s})\n".format(
                    e.errno, str(e)
                )
            )

            raise SystemExit(1)

        # redirect standard file descriptors
        stdout.flush()
        stderr.flush()

        maxfd = getrlimit(RLIMIT_NOFILE)[1]
        if maxfd == RLIM_INFINITY:
            maxfd = 2048

        closerange(0, maxfd)

        si = open(self.stdin, "r")
        so = open(self.stdout, "a+")
        se = open(self.stderr, "a+")

        dup2(si.fileno(), stdin.fileno())
        dup2(so.fileno(), stdout.fileno())
        dup2(se.fileno(), stderr.fileno())

        self.fire(writepid())
        self.fire(daemonized(self))
开发者ID:AdricEpic,项目名称:circuits,代码行数:55,代码来源:daemon.py


示例16: enableEchoMode

def enableEchoMode():
    """
    Enable echo mode in the terminal. Return True if the echo mode is set
    correctly, or False if the mode was already set.
    """
    fd = stdin.fileno()
    state = tcgetattr(fd)
    if state[TERMIO_LFLAGS] & ECHO:
        return False
    state[TERMIO_LFLAGS] = state[TERMIO_LFLAGS] | ECHO
    tcsetattr(fd, TCSADRAIN, state)
    return True
开发者ID:cherry-wb,项目名称:segvault,代码行数:12,代码来源:terminal.py


示例17: getch

 def getch():
     """
         A getch for Linux Systems.
     """
     file_descriptor = stdin.fileno()
     old_settings = tcgetattr(file_descriptor)
     try:
         setraw(file_descriptor)
         character = stdin.read(1)
     finally:
         tcsetattr(file_descriptor, TCSADRAIN, old_settings)
     return character
开发者ID:ParthKolekar,项目名称:mazetool,代码行数:12,代码来源:mazetool.py


示例18: read_colormap

def read_colormap():
    print "Reading color map from terminal, please wait... ",
    import tty, termios
    fd = stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(fd)
        for n, c in queryall():
            CLUT[n] = c
        print '\r\033[K',
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
开发者ID:rgm3,项目名称:bonepeg,代码行数:12,代码来源:calc256.py


示例19: __call__

 def __call__(self, refresh):
     import tty, termios
     while True:
         fd = stdin.fileno()
         old_settings = termios.tcgetattr(fd)
         try:
             tty.setraw(stdin.fileno())
             rlist, _, _ = select([stdin], [], [], refresh)
             if not rlist:
                 return 'rr'
             ch = stdin.read(1)
             if not ch.isalnum():
                 if ch == '\x1b':
                     return 'qq'
                 # if we have an arrow
                 if ch == "\x1B":
                     stdin.read(2)
                 return ch
         finally:
             termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
         return ch
开发者ID:fransua,项目名称:slurm_utils,代码行数:21,代码来源:monitor.py


示例20: getch_non_blocking_2

def getch_non_blocking_2():
    fd = stdin.fileno()
    old = termios.tcgetattr(fd)
    try:
        tty.setraw(fd)
        if select([stdin], [], [], 0)[0]:
            char = stdin.read(1)
            return char
        else:
            return None
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old)
开发者ID:dandavison,项目名称:misc,代码行数:12,代码来源:getchs_2.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stdin.read函数代码示例发布时间:2022-05-27
下一篇:
Python stderr.write函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap