I used to use this snippet to monitor the progress of of a multiprocess. Though, now q.qsize() stopped working and only returns zeros. Is there a replacement for what q.qsize()
used to do formerly? Or is there a better way of doing that?
from multiprocessing import Pool, Manager, cpu_count
def process(args):
'''
Pickleable function for (parallel) processing.
Expects a dictionary with keys:
Mandatory:
- 'filename': 'path to file to be processed',
...
Optional:
- 'queue': instance of multiprocessing.Manager().Queue()
'''
filename = args['filename']
mode = args['mode']
if 'queue' in args.keys():
q = args['queue']
q.put('filename')
return do_something_with(filename)
...
pool = Pool(processes=nthreads)
m = Manager()
q = m.Queue()
# prepare args...
results = pool.map_async(process, args)
# monitor progress
while True:
if results.ready():
break
else:
size = q.qsize()
self.progress = int(100 * (size / self.n_files))
time.sleep(1)
self.progress = 100