當前位置: 首頁>>代碼示例>>Python>>正文


Python os.forkpty方法代碼示例

本文整理匯總了Python中os.forkpty方法的典型用法代碼示例。如果您正苦於以下問題:Python os.forkpty方法的具體用法?Python os.forkpty怎麽用?Python os.forkpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.forkpty方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: forkpty_gevent

# 需要導入模塊: import os [as 別名]
# 或者: from os import forkpty [as 別名]
def forkpty_gevent():
            """
            Forks the process using :func:`os.forkpty` and prepares the
            child process to continue using gevent before returning.

            Returns a tuple (pid, master_fd). The `master_fd` is *not* put into
            non-blocking mode.

            Availability: Some Unix systems.

            .. seealso:: This function has the same limitations as :func:`fork_gevent`.

            .. versionadded:: 1.1b5
            """
            pid, master_fd = _raw_forkpty()
            if not pid:
                reinit()
            return pid, master_fd 
開發者ID:leancloud,項目名稱:satori,代碼行數:20,代碼來源:os.py

示例2: forkpty_and_watch

# 需要導入模塊: import os [as 別名]
# 或者: from os import forkpty [as 別名]
def forkpty_and_watch(callback=None, loop=None, ref=False, forkpty=forkpty_gevent):
                """
                Like :func:`fork_and_watch`, except using :func:`forkpty_gevent`.

                Availability: Some Unix systems.

                .. versionadded:: 1.1b5
                """
                result = []

                def _fork():
                    pid_and_fd = forkpty()
                    result.append(pid_and_fd)
                    return pid_and_fd[0]
                fork_and_watch(callback, loop, ref, _fork)
                return result[0] 
開發者ID:leancloud,項目名稱:satori,代碼行數:18,代碼來源:os.py

示例3: open

# 需要導入模塊: import os [as 別名]
# 或者: from os import forkpty [as 別名]
def open(self, loop):
        pid, self.fd = os.forkpty()
        if pid == 0:
            if bot.settings.get("user") and "login" in bot.settings.get("user") and bot.settings.get("user")["login"]:
                    os.execv(bot.settings.get("terminal")["su_path"],
                             [bot.settings.get("terminal")["su_path"], "-", bot.settings.get("user")["login"], "-s", bot.settings.get("terminal")["shell_path"]])
            else:
                os.execv(bot.settings.get("terminal")["shell_path"], [bot.settings.get("terminal")["shell_path"], ])

            sys.exit(0)
        else:
            self.status = "working"

            pty_output = threading.Thread(target=self.watch_output)
            pty_output.start()

            self.update_output(loop)

        return self 
開發者ID:Adikso,項目名稱:BashBot,代碼行數:21,代碼來源:bash.py

示例4: fork

# 需要導入模塊: import os [as 別名]
# 或者: from os import forkpty [as 別名]
def fork():
    """fork() -> (pid, master_fd)
    Fork and make the child a session leader with a controlling terminal."""

    try:
        pid, fd = os.forkpty()
    except (AttributeError, OSError):
        pass
    else:
        if pid == CHILD:
            try:
                os.setsid()
            except OSError:
                # os.forkpty() already set us session leader
                pass
        return pid, fd

    master_fd, slave_fd = openpty()
    pid = os.fork()
    if pid == CHILD:
        # Establish a new session.
        os.setsid()
        os.close(master_fd)

        # Slave becomes stdin/stdout/stderr of child.
        os.dup2(slave_fd, STDIN_FILENO)
        os.dup2(slave_fd, STDOUT_FILENO)
        os.dup2(slave_fd, STDERR_FILENO)
        if (slave_fd > STDERR_FILENO):
            os.close (slave_fd)

        # Explicitly open the tty to make it become a controlling tty.
        tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
        os.close(tmp_fd)
    else:
        os.close(slave_fd)

    # Parent and child process.
    return pid, master_fd 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:41,代碼來源:pty.py

示例5: forkpty

# 需要導入模塊: import os [as 別名]
# 或者: from os import forkpty [as 別名]
def forkpty(*args, **kwargs):
                    """
                    Like :func:`fork`, but using :func:`forkpty_gevent`.

                    This implementation of ``forkpty`` is a wrapper for :func:`forkpty_and_watch`
                    when the environment variable ``GEVENT_NOWAITPID`` is *not* defined.
                    This is the default and should be used by most applications.

                    .. versionadded:: 1.1b5
                    """
                    # take any args to match fork_and_watch
                    return forkpty_and_watch(*args, **kwargs) 
開發者ID:leancloud,項目名稱:satori,代碼行數:14,代碼來源:os.py


注:本文中的os.forkpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。