Skip to content

Commit

Permalink
Terminate pool when kernel is interrupted on a jupyter notebook
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
zeehio committed Apr 30, 2019
1 parent d4feda3 commit aadd6d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
parmap (1.5.1.9000)

* Fix #14: Workers should be stopped also when the kernel is interrupted
on a jupyter notebook. Thanks to @wjaskowski for the report.
* Fix #21: Now it is possible to use pm_pbar with pm_pool. Thanks
to @CarloNicolini for the report.

Expand Down
18 changes: 15 additions & 3 deletions parmap/parmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ def _map_or_starmap(function, iterable, args, kwargs, map_or_starmap):
repeat(kwargs)),
chunksize)
output = result.get()
finally:
except:
if close_pool:
pool.terminate()
raise
else:
if close_pool:
pool.close()
pool.join()
Expand All @@ -264,7 +268,11 @@ def _map_or_starmap(function, iterable, args, kwargs, map_or_starmap):
repeat(list(args)),
repeat(kwargs)),
chunksize)
finally:
except:
if close_pool:
pool.terminate()
raise
else:
if close_pool:
pool.close()
# Progress bar:
Expand Down Expand Up @@ -415,7 +423,11 @@ def _map_or_starmap_async(function, iterable, args, kwargs, map_or_starmap):
repeat(kwargs)),
chunksize = chunksize,
callback = callback)
finally:
except:
if close_pool:
pool.terminate()
raise
else:
if close_pool:
pool.close()
result = _ParallelAsyncResult(result, pool)
Expand Down

0 comments on commit aadd6d4

Please sign in to comment.