python - 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()
问题:我将如何使用仅在子进程/线程和重新生成子进程时才会做出反应的父进程。
解决方案
推荐阅读
- php - Laravel agroup 数据由 idParent
- mysql - 为什么请求正文向服务器端发送值 undefined 或 null?
- python - 升级 Anaconda Navigator 3 后无法启动 Spyder
- node.js - 同时按两个字符串值对 mongodb 进行排序
- ios - 为 iOS 15 中的不同部分设置新的 sectionHeaderTopPadding 属性
- mysql - 我可以在“插入前”触发器中比较两列的值吗?
- python - Python C API,线程安全
- netlify - NPM pro-gallery,不在实时站点中加载图像
- spring - 在 Spring Boot 应用程序启动之前打印 Hello World
- python-requests - 如何在 HTML 标签中运行 JavaScript 代码?