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(), andmultiprocessing.Pool.starmap_async().First, the
terminateandjoinmethods ofPoolare attempted within a daemon thread with a 5-second timeout. If the timeout is reached, each process in the pool is sent aCTRL_C_EVENTto shut it down somewhat forcefully. If the process is still alive, aCTRL_BREAK_EVENTis sent to shut it down more forcefully. After the signals are sent to the processes, theterminatemethod is called again.Important
The
multiprocessing.Poolcontext manager must still be used to ensure that theclosemethod is still called after the pool is terminated.