我想使用python自动化一些大数据文件处理。困惑python subprocess内循环
的处理的垂耳被链接,即SCRIPT1写入一个文件,即随后由SCRIPT2处理,则通过script3等SCRIPT2的输出
我正在使用的螺纹上下文子模块。
我有一个类创建链接脚本的元组 (“scr1.sh”,“scr2.sh”,“scr3.sh”)。
然后使用像
for script in scriplist:
subprocess.call(script)
我的问题呼叫中的另一类是在for循环,是每个脚本后,才subprocess.call(SCRIPT1)称为返回一个成功RETCODE?
或者是因为我使用的是subprocess.call,所有三个都被调用一个接一个,没有使用“睡眠”或“等待”,我想确保第二个脚本只在第一个脚本启动后才开始过度。
编辑:pydoc说 “subprocess.call(* popenargs,** kwargs) 带参数运行命令,等待命令完成,然后返回returncode属性。
所以在for循环(上面)中,是否在迭代到下一个脚本之前等待每个retcode。
我是线程新手。我在此附上运行分析的类的精简代码。 subprocess.call循环是这个类的一部分。
class ThreadedDataProcessor(Thread):
def __init__(self, in_queue, out_queue):
# Uses Queue
Thread.__init__(self)
self.in_queue = in_queue
self.out_queue = out_queue
def run(self):
while True:
path = self.in_queue.get()
if path is None:
break
myprocessor = ProcessorScriptCreator(path)
scrfiles = myprocessor.create_and_return_shell_scripts()
for index,file in enumerate(scrfiles):
subprocess.call([file])
print "CALLED%s%s" % (index,file) *5
#report(myfile.describe())
#report("Done %s" % path)
self.out_queue.put(path)
in_queue = Queue()
抱歉不知道关于stackoverflow上的“接受率”。 – harijay 2010-10-27 11:27:22
@Rafe Kettler:我在文档中阅读关于subprocess.call()的部分。如果我没有弄错,for循环会在下一轮for循环之前等待每个retcode - 是这种情况吗? – harijay 2010-10-27 15:26:42