简体   繁体   English

python:subprocess.call线程问题

[英]python: subprocess.call threads problem

Hello people within the while True processing never ends, even if I use q.task_done, what is wrong? 您好,虽然我使用q.task_done,但True处理过程永远不会结束,这是怎么回事?


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()

Thanks 谢谢

What are the program listings for abc.py and def.py? abc.py和def.py的程序清单是什么? Are you sure that the commands you are executing ever end? 您确定要执行的命令永远结束吗? Try running it with the two subprocess.call() lines commented out and see if it works as intended. 尝试用注释掉的两个subprocess.call()行运行它,看看它是否按预期工作。 If it suddenly works, then the problem is somewhere related to the scripts you're calling outside of the code. 如果突然生效,则问题出在与您在代码外部调用的脚本有关的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM