【发布时间】:2016-02-21 02:51:15
【问题描述】:
我需要在没有任何交互的情况下并行运行 2 个不同的 python 脚本:script1 和 script2。它们的位置如下:
dir0 包含文件 jobcript.py 和 2 个名为 dir1、dir2 的目录。 dir1 包含 script1,dir2 包含 script2。
jobscript.txt 中有以下几行。
#!/usr/bin/python
import subprocess
exit_code1 = subprocess.call(["python", "./dir1/script1", "-o"], shell=False)
exit_code2 = subprocess.call(["python", "./dir2/script2", "-o"], shell=False)
我在 linux 中运行了以下命令:
$ python jobscript.py -o
但这是连续运行的。如何并行运行它们?非常感谢您的解决方案!
【问题讨论】:
-
sbatch 安装了吗?
-
还有你为什么要使用 bash shebang 行运行 python 脚本?
-
@shafeen 实际上我是 linux 的新手。努力学习。你能更正代码吗?谢谢。
-
shebang 行 (
#!) 是文件顶部的行,告诉它它是什么类型的脚本,对于 python,您应该使用#!/bin/python或#!/usr/bin/env python -
@我明白你的意思了!我修改了这样的代码:#!/usr/bin/python import subprocess.这是工作!谢谢你的主意!现在你能告诉我如何在不交互的情况下在不同的处理器中并行完成这两项工作吗?