File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 3232# ---------------------------------------------
3333_pool_lock = threading .Lock ()
3434_pool : ProcessPoolExecutor | None = None
35+ _pool_cleanup_registered = False
3536_user_apps : list [str ] = []
3637_logger = logging .getLogger (__name__ )
3738
@@ -52,13 +53,16 @@ def _shutdown_pool_at_exit() -> None:
5253 _pool = None
5354
5455
55- atexit .register (_shutdown_pool_at_exit )
56-
57-
5856def _get_pool () -> ProcessPoolExecutor :
59- global _pool
57+ global _pool , _pool_cleanup_registered
6058 with _pool_lock :
6159 if _pool is None :
60+ if not _pool_cleanup_registered :
61+ # Register the shutdown at exit at creation time (rather than at import time)
62+ # to make sure it's executed earlier in the shutdown sequence.
63+ atexit .register (_shutdown_pool_at_exit )
64+ _pool_cleanup_registered = True
65+
6266 # Single worker process as requested
6367 _pool = ProcessPoolExecutor (
6468 max_workers = 1 ,
You can’t perform that action at this time.
0 commit comments