【发布时间】:2020-07-11 00:12:21
【问题描述】:
如何保持循环继续进行,同时让一些进程在循环中等待其他进程? (说明见下面代码,用代码解释更有意义)
for i in range(0, len(my_list), batch_size):
current_batch = my_list[i:i+batch_size]
download_processes = [Popen('do stuff')] # NOT ACTUAL CODE. This downloads files.
_ = [p.wait() for p in download_processes] # wait until all files above download before executing the code below
more_processes = [Popen('do stuff')] # NOT ACTUAL CODE. This zips the downloaded files
# execute yet more processes (that process the zips files) when "more_processes" end, but keep the loop going to start downloading more files
【问题讨论】:
标签: python multiprocessing popen