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


Python os.tcgetpgrp方法代码示例

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


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

示例1: foreground_processes

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def foreground_processes(self) -> List[ProcessDesc]:
        if self.child_fd is None:
            return []
        try:
            pgrp = os.tcgetpgrp(self.child_fd)
            foreground_processes = processes_in_group(pgrp) if pgrp >= 0 else []

            def process_desc(pid: int) -> ProcessDesc:
                ans: ProcessDesc = {'pid': pid, 'cmdline': None, 'cwd': None}
                with suppress(Exception):
                    ans['cmdline'] = cmdline_of_process(pid)
                with suppress(Exception):
                    ans['cwd'] = cwd_of_process(pid) or None
                return ans

            return [process_desc(x) for x in foreground_processes]
        except Exception:
            return [] 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:20,代码来源:child.py

示例2: initialise

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def initialise(self):
        if not self.enabled:
            return
        if termios is None:
            self.enabled = False
            return
        try:
            self.tty = open("/dev/tty", "w+")
            os.tcgetpgrp(self.tty.fileno())
            self.clean_tcattr = termios.tcgetattr(self.tty)
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = self.clean_tcattr
            new_lflag = lflag & (0xffffffff ^ termios.ICANON)
            new_cc = cc[:]
            new_cc[termios.VMIN] = 0
            self.cbreak_tcattr = [
                iflag, oflag, cflag, new_lflag, ispeed, ospeed, new_cc]
        except Exception:
            self.enabled = False
            return 
开发者ID:pnprog,项目名称:goreviewpartner,代码行数:21,代码来源:terminal_input.py

示例3: _is_daemon

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def _is_daemon():
    # The process group for a foreground process will match the
    # process group of the controlling terminal. If those values do
    # not match, or ioctl() fails on the stdout file handle, we assume
    # the process is running in the background as a daemon.
    # http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics
    try:
        is_daemon = os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno())
    except io.UnsupportedOperation:
        # Could not get the fileno for stdout, so we must be a daemon.
        is_daemon = True
    except OSError as err:
        if err.errno == errno.ENOTTY:
            # Assume we are a daemon because there is no terminal.
            is_daemon = True
        else:
            raise
    return is_daemon 
开发者ID:openstack,项目名称:oslo.service,代码行数:20,代码来源:service.py

示例4: check_dir

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def check_dir(self, out_dir):
        if os.path.exists(out_dir):
            #check if the process is run in background
            try: 
                if os.getpgrp() == os.tcgetpgrp(sys.stdout.fileno()):
                    print  self.user_message % out_dir
                    user_input = raw_input()
                    while user_input not in ["1", "2", "3"]:
                        user_input = raw_input().strip()
                    if user_input == "1":
                        return False 
                    if user_input == "2":
                        shutil.rmtree(out_dir)
                        os.mkdir(out_dir)
                        return True 
                    if user_input == "3":
                        sys.exit(1)
                else:
                    sys.stderr.write(self.error_message % out_dir)
            except OSError:
                    sys.stderr.write(self.error_message % out_dir)
        else: 
            os.mkdir(out_dir)
            return True 
开发者ID:aweimann,项目名称:traitar,代码行数:26,代码来源:traitar.py

示例5: determine_interactive

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def determine_interactive(self):
		"""Determine whether we're in an interactive shell.
		Sets interactivity off if appropriate.
		cf http://stackoverflow.com/questions/24861351/how-to-detect-if-python-script-is-being-run-as-a-background-process
		"""
		try:
			if not sys.stdout.isatty() or os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno()):
				self.interactive = 0
				return False
		except Exception:
			self.interactive = 0
			return False
		if self.interactive == 0:
			return False
		return True 
开发者ID:ianmiell,项目名称:shutit,代码行数:17,代码来源:shutit_global.py

示例6: tcgetpgrp

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def tcgetpgrp(self):
        return os.tcgetpgrp(self.fileno()) 
开发者ID:kdart,项目名称:pycopia,代码行数:4,代码来源:UserFile.py

示例7: tcgetpgrp

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def tcgetpgrp(self):
        return os.tcgetpgrp(self._fo.fileno()) 
开发者ID:kdart,项目名称:pycopia,代码行数:4,代码来源:expect.py

示例8: pid_for_cwd

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def pid_for_cwd(self) -> Optional[int]:
        with suppress(Exception):
            assert self.child_fd is not None
            pgrp = os.tcgetpgrp(self.child_fd)
            foreground_processes = processes_in_group(pgrp) if pgrp >= 0 else []
            if len(foreground_processes) == 1:
                return foreground_processes[0]
        return self.pid 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:10,代码来源:child.py

示例9: stop_was_requested

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def stop_was_requested(self):
        """Check whether a 'keyboard stop' instruction has been sent.

        Returns true if ^X has been sent on the controlling terminal.

        Consumes all available input on /dev/tty.

        """
        if not self.enabled:
            return False
        # Don't try to read the terminal if we're in the background.
        # There's a race here, if we're backgrounded just after this check, but
        # I don't see a clean way to avoid it.
        if os.tcgetpgrp(self.tty.fileno()) != os.getpid():
            return False
        try:
            termios.tcsetattr(self.tty, termios.TCSANOW, self.cbreak_tcattr)
        except EnvironmentError:
            return False
        try:
            seen_ctrl_x = False
            while True:
                c = os.read(self.tty.fileno(), 1)
                if not c:
                    break
                if c == "\x18":
                    seen_ctrl_x = True
        except EnvironmentError:
            seen_ctrl_x = False
        finally:
            termios.tcsetattr(self.tty, termios.TCSANOW, self.clean_tcattr)
        return seen_ctrl_x 
开发者ID:pnprog,项目名称:goreviewpartner,代码行数:34,代码来源:terminal_input.py

示例10: startLog

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def startLog(self):
        """Starts the log to path.  The parent process becomes the "slave"
        process: its stdin, stdout, and stderr are redirected to a pseudo tty.
        A child logging process controls the real stdin, stdout, and stderr,
        and writes stdout and stderr both to the screen and to the logfile
        at path.
        """
        self.restoreTerminalControl = (sys.stdin.isatty() and
            os.tcgetpgrp(0) == os.getpid())

        masterFd, slaveFd = os.openpty()
        signal.signal(signal.SIGTTOU, signal.SIG_IGN)

        pid = os.fork()
        if pid:
            # make parent process the pty slave - the opposite of
            # pty.fork().  In this setup, the parent process continues
            # to act normally, while the child process performs the
            # logging.  This makes it simple to kill the logging process
            # when we are done with it and restore the parent process to
            # normal, unlogged operation.
            os.close(masterFd)
            self._becomeLogSlave(slaveFd, pid)
            return
        try:
            os.close(slaveFd)
            for writer in self.writers:
                writer.start()
            logger = _ChildLogger(masterFd, self.lexer,
                                  self.restoreTerminalControl, self.withStdin)
            try:
                logger.log()
            finally:
                self.lexer.close()
        finally:
            os._exit(0) 
开发者ID:sassoftware,项目名称:conary,代码行数:38,代码来源:logger.py

示例11: switch_pgid

# 需要导入模块: import os [as 别名]
# 或者: from os import tcgetpgrp [as 别名]
def switch_pgid(self):
        try:
            if os.getpgrp() != os.tcgetpgrp(0):
                self.__old_pgid = os.getpgrp()
                os.setpgid(0, os.tcgetpgrp(0))
            else:
                self.__old_pgid = None
        except OSError:
            self.__old_pgid = None 
开发者ID:sassoftware,项目名称:conary,代码行数:11,代码来源:__init__.py


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