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