首页 > 解决方案 > Python - 如果关闭则生成子进程窗口

问题描述

情况:我希望 Python 控制台窗口保持打开状态。我能想到的最简单的方法(或唯一的方法)是拥有一个父进程,该进程生成一个生成 CLI 窗口的守护线程/进程,如果有.join(),只需再次生成它。

import threading

def prompt():
    while True:
        userDecision = input("Enter option: ")
        if userDecision == X:
            doSomething()

if __name__ == '__main__':
    while True:
        prompt_t = threading.Thread(target=prompt)
        prompt_thread.start()
        prompt_thread.join()
        doStuffWhenThreadEnds()

#Something tells me that I should be spawning
#a shell instead of calling a function.

问题:我对这些模块不是很熟悉。

.join()问题:我将如何使用仅在子进程/线程和重新生成子进程时才会做出反应的父进程。

标签: pythonmultithreadingsubprocess

解决方案


推荐阅读