python:subprocess.call线程问题

时间:2011-02-23 22:57:00

标签: python multithreading subprocess

Hello in people while while True processing永远不会结束,即使我使用q.task_done,有什么问题?


fileQueue = Queue()
def submit(i, q):
    global filespath
    while True:
      filename = q.get()
      retVT = subprocess.call("python abc.py -f %s" % (filespath + filename), shell=True, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT)
      retTH = subprocess.call("python def.py -a %s" % (filename), shell= True, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT)
      q.task_done()

def main(): global fileQueue
num_threads = fileQueue.qsize() for i in range(num_threads): worker = Thread(target=submit, args=(i, fileQueue)) worker.setDaemon(True) worker.start() fileQueue.join()
print "Done"

if name == 'main': main()

由于

1 个答案:

答案 0 :(得分:0)

abc.py和def.py的节目列表是什么?你确定你执行的命令结束了吗?尝试使用注释掉的两个subprocess.call()行运行它,看看它是否按预期工作。如果它突然起作用,那么问题就在于你在代码之外调用的脚本。