我想知道工人什么时候完成,以便我可以释放资源作为任何工人的最后行动。或者,我也可以在主进程上释放这些资源,但我需要在每个工作人员之后一个一个地释放这些资源(与在所有工作人员完成后释放一次相反)。
我正在运行我的工作人员,跟踪进度和使用的 PID:
from pathos.multiprocessing import ProcessingPool
pool = ProcessingPool(num_workers)
pool.restart(force=True)
# Loading PIDs of workers with my get_pid() function:
pids = pool.map(get_pid, xrange(num_workers))
try:
results = pool.amap(
exec_func,
exec_args,
)
counter = 0
while not results.ready():
sleep(2)
if counter % 60 == 0:
log.info('Waiting for children running in pool.amap() with PIDs: {}'.format(pids))
counter += 1
results = results.get()
# Attempting to close pool...
pool.close()
# The purpose of join() is to ensure that a child process has completed
# before the main process does anything.
# Attempting to join pool...
pool.join()
except:
# Try to terminate the pool in case some worker PIDs still run:
cls.hard_kill_pool(pids, pool)
raise
由于负载平衡,很难知道哪个工作将是工作人员的最后一个工作。有什么方法可以知道一些工人已经不活跃了?
我正在使用 pathos 0.2.0 版。