且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何生成一个单独的 python 进程?

更新时间:2022-06-22 04:24:10

execfile

直截了当的方法:

execfile

The straightforward approach:

execfile('main.py')

子流程

提供对输入和输出的细粒度控制,可以在后台运行进程:

Subprocess

Offers fine-grained control over input and output, can run processes in background:

import subprocess as sp
process=sp.Popen('other_file.py', shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
out, err = process.communicate()  # The output and error streams.