【发布时间】:2012-08-22 09:03:46
【问题描述】:
我使用大量的os.system 调用在 for 循环中创建后台进程。如何等待所有后台进程结束?
os.wait 告诉我没有子进程。
ps:我正在使用 Solaris
这是我的代码:
#!/usr/bin/python
import subprocess
import os
pids = []
NB_PROC=30
for i in xrange(NB_PROC):
p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True)
pids.insert(0,p)
p = subprocess.Popen("(time wget http://site.com/test.php 2>&1 | grep real )&", shell=True)
pids.insert(0,p)
for i in xrange(NB_PROC*2):
pids[i].wait()
os.system("rm test.php*")
【问题讨论】:
-
os.system已弃用,尝试使用subprocess模块 -
os.system 似乎没有被弃用:docs.python.org/library/os.html 但即使使用子进程我也有同样的错误