同时运行多个python文件

时间:2014-05-11 11:31:45

标签: python

我了解我们可以使用Python multiprocessing模块并为此导入Process

但是我们的Python代码是什么,假设我们想要同时执行a.pyb.py这两个文件。

我希望Python脚本能够包含上述内容,而不是从两个命令提示符中运行文件。

以下是框架:

import multiprocessing

def worker(file):
    #your subprocess code

if __name__ == '__main__':
    files = ["path/to/file1.py","path/to/file2.py","path/to/file3.py"]
    for i in files:
        p = multiprocessing.Process(target=worker(i))
        p.start()

什么是子流程代码?

1 个答案:

答案 0 :(得分:0)

只需打开两个命令提示符(在Windows中)或终端(在其他操作系统'中)。然后在一个窗口中运行每个文件。