python:subprocess.call线程问题
你好,同时真正的处理永远不会结束,即使我使用 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():
全局文件队列
num_threads = fileQueue.qsize()
对于范围内的 i(num_threads):
工人=线程(目标=提交,args=(i,文件队列))
worker.setDaemon(True)
工作人员.start()
fileQueue.join()
如果 name == 'main' 则打印“完成”
:
主要的()
谢谢
Hello people within the while True processing never ends, even if I use q.task_done, what is wrong?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
abc.py 和 def.py 的程序列表是什么?您确定正在执行的命令会结束吗?尝试使用注释掉的两行 subprocess.call() 来运行它,看看它是否按预期工作。如果它突然起作用,那么问题就与您在代码之外调用的脚本有关。
What are the program listings for abc.py and 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. If it suddenly works, then the problem is somewhere related to the scripts you're calling outside of the code.