简体   繁体   中英

python: subprocess.call threads problem

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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