def easy_par(f, sequence):
from multiprocessing import Pool
poolsize=len(sequence)
if poolsize > 16:
poolsize = 16
pool = Pool(processes=poolsize)
try:
# f is given sequence. guaranteed to be in order
cleaned=False
result = pool.map(f, sequence)
cleaned = [x for x in result if not x is None]
#cleaned = asarray(cleaned)
# not optimal but safe
except KeyboardInterrupt:
pool.terminate()
except Exception as e:
print('got exception: %r' % (e,))
if not args.force:
print("Terminating the pool")
pool.terminate()
finally:
pool.close()
pool.join()
return cleaned
评论列表
文章目录