File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 1919import asyncio
2020import os
2121import time
22- import atexit
2322from .user_app_loader import load_user_app
2423from .runtime import execution_context
2524import logging
@@ -63,10 +62,18 @@ def _get_pool() -> ProcessPoolExecutor:
6362 with _pool_lock :
6463 if _pool is None :
6564 if not _pool_cleanup_registered :
66- # Register the shutdown at exit at creation time (rather than at import time)
67- # to make sure it's executed earlier in the shutdown sequence.
68- atexit .register (_shutdown_pool_at_exit )
69- _pool_cleanup_registered = True
65+ # CRITICAL: register with threading's early-exit list
66+ reg = getattr (threading , "_register_atexit" , None )
67+ if callable (reg ):
68+ reg (_shutdown_pool_at_exit ) # goes ahead of normal atexit
69+ _pool_cleanup_registered = True
70+ else :
71+ # Fallback for odd Pythons: normal atexit (will run later)
72+ import atexit
73+
74+ if not _pool_cleanup_registered :
75+ atexit .register (_shutdown_pool_at_exit )
76+ _pool_cleanup_registered = True
7077
7178 # Single worker process as requested
7279 _pool = ProcessPoolExecutor (
You can’t perform that action at this time.
0 commit comments