Вот как работает скрипт Python "B" " выполняется из скрипта Python "A":
Код: Выделить всё
process = subprocess.Popen(["gnome-terminal", "--", "bash", "-c", "python scriptB.py"])
Код: Выделить всё
print(process.pid) # prints 5152
print(psutil.Process(process.pid).children(recursive=True)) # len is 0
parent = psutil.Process(process.pid).parent()
print(parent) # prints 5151
parent = psutil.Process(parent).parent()
print(parent) # prints 4372
Когда я запускаю ps ax, я получаю следующее:
Код: Выделить всё
5151 pts/0 S+ 0:00 python test_process.py
5152 pts/0 Z+ 0:00 [gnome-terminal]
5158 pts/1 Rs+ 0:10 /anaconda3/envs/env1/bin/python3 scriptB.py
5164 pts/2 R+ 0:00 ps ax
Обновление:
В версии для Windows , я использую:
Код: Выделить всё
process = subprocess.Popen(["cmd", "/c", f"start cmd /k python scriptB.py"])
Подробнее здесь: https://stackoverflow.com/questions/784 ... rom-python