Skip to content
Snippets Groups Projects
Commit 2f53006d authored by Colm Talbot's avatar Colm Talbot Committed by Colm Talbot
Browse files

DEV: make pool terminate on exit

parent 6c6201d7
No related branches found
No related tags found
No related merge requests found
......@@ -727,16 +727,29 @@ class Sampler(object):
if self.npool in (1, None) or getattr(self, "pool", None) is not None:
self._log_interruption(signum=signum)
self.write_current_state()
self._close_pool()
self._close_pool(hard=True)
if self.hard_exit:
os._exit(self.exit_code)
else:
sys.exit(self.exit_code)
def _close_pool(self):
def _close_pool(self, hard=False):
"""
Close the worker pool.
Parameters
==========
hard: bool
Whether to terminate the pool or just close it. Terminating the
pool will kill all running jobs, closing it will wait for them to
finish.
"""
if getattr(self, "pool", None) is not None:
logger.info("Starting to close worker pool.")
self.pool.close()
if hard:
self.pool.terminate()
else:
self.pool.close()
self.pool.join()
self.pool = None
self.kwargs["pool"] = self.pool
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment