pymead.utils.pymead_mp.pool_terminate_multi_tiered#

pool_terminate_multi_tiered(pool: Pool)[source]#

Multi-tiered multiprocessing pool termination function that tries several pool termination methods in sequence from least forceful to most forceful to guarantee that the pool is closed, especially when a significant portion of the CPU and RAM are being used. This function is intended for use with asynchronous parallel function calls like multiprocessing.Pool.apply_async(), multiprocessing.Pool.map_async(), multiprocessing.Pool.imap(), multiprocessing.Pool.imap_unordered(), and multiprocessing.Pool.starmap_async().

First, the terminate and join methods of Pool are attempted within a daemon thread with a 5-second timeout. If the timeout is reached, each process in the pool is sent a CTRL_C_EVENT to shut it down somewhat forcefully. If the process is still alive, a CTRL_BREAK_EVENT is sent to shut it down more forcefully. After the signals are sent to the processes, the terminate method is called again.

Important

The multiprocessing.Pool context manager must still be used to ensure that the close method is still called after the pool is terminated.