Skip to content

Commit

Permalink
Merge pull request #43 from johntruckenbrodt/bugfix/multiprocess_context
Browse files Browse the repository at this point in the history
[multiprocess] use ProcessPool context manager
  • Loading branch information
johntruckenbrodt authored Apr 11, 2024
2 parents f510643 + 247edaa commit 19fce1a
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions spatialist/ancillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,14 @@ def wrapper(**kwargs):
widgets = [pb.Percentage(), pb.Bar(), pb.Timer(), ' ', pb.ETA()]
progress = pb.ProgressBar(max_value=jobs, widgets=widgets).start()

try:
pool = mp.ProcessPool(processes=cores)
except NameError:
raise ImportError("package 'pathos' could not be imported")
results = pool.amap(lambda x: wrapper(**x), processlist)
while not results.ready():
left = results._number_left * chunksize
done = jobs - left if left <= jobs else 0
if pbar:
progress.update(done)

results = results.get()
pool.close()
pool.join()
with mp.ProcessPool(processes=cores) as pool:
results = pool.amap(lambda x: wrapper(**x), processlist)
while not results.ready():
left = results._number_left * chunksize
done = jobs - left if left <= jobs else 0
if pbar:
progress.update(done)
results = results.get()

if progress is not None:
progress.finish()
Expand Down

0 comments on commit 19fce1a

Please sign in to comment.