python - python中的问题试图打开2个终端
问题描述
我正在尝试创建一个允许您同时打开 2 个终端的 python 脚本,它工作正常,但是如果我尝试将它插入到循环中,则第二个终端不会打开并且它会跳到下一条语句,这里是工作正常的代码:
from subprocess import Popen, PIPE, CREATE_NEW_CONSOLE
import multiprocessing as mp
import threading as th
def run(command):
cmd = Popen(command, PIPE, creationflags=CREATE_NEW_CONSOLE)
com, err = cmd.communicate()
print(com,err)
if __name__ == "__main__":
mp.freeze_support()
command = f"python testFile.py" # or command = f"testFile.exe"
process = mp.Process(target=run, args= (command,))
process.start()
input("Wait ")
正如我所说,这很好用,但是如果我尝试将其插入循环中,则第二个终端不会打开:
from subprocess import Popen, PIPE, CREATE_NEW_CONSOLE
import multiprocessing as mp
import threading as th
def run(command):
cmd = Popen(command, PIPE, creationflags=CREATE_NEW_CONSOLE)
com, err = cmd.communicate()
print(com,err)
while True:
if __name__ == "__main__":
mp.freeze_support()
command = f"python testFile.py" # or command = f"testFile.exe"
process = mp.Process(target=run, args= (command,))
process.start()
input("Wait ")
解决方案
推荐阅读
- python - 使用 python 字典时无法解压不可迭代的 int 对象
- python - python - 'AttributeError:'NoneType'对象在网页抓取时没有属性'text'
- php - 使用 API 向 xero 添加附件时不允许使用 pdf 扩展名
- css - 如何在不冲突的情况下处理宽度和高度?
- powerbi - Distintcount 与多个冲突的过滤器
- javascript - 自定义验证函数未调用
- wso2 - WSO2 EI 从 Oracle Blob 返回图像/jpeg
- javascript - 如何使用 antd 作为基础库来使用 rollup 创建自定义库?
- python - 无法从“transformers.modeling_distilbert”导入名称“DISTILBERT_PRETRAINED_MODEL_ARCHIVE_MAP”
- makefile - 在makefile中使用ifeq语句,即使正确缩进制表符也缺少分隔符