File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed
Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change 1919import asyncio
2020import os
2121import time
22+ import atexit
2223from .user_app_loader import load_user_app
2324from .runtime import execution_context
2425import logging
@@ -62,18 +63,10 @@ def _get_pool() -> ProcessPoolExecutor:
6263 with _pool_lock :
6364 if _pool is None :
6465 if not _pool_cleanup_registered :
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
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
7770
7871 # Single worker process as requested
7972 _pool = ProcessPoolExecutor (
You can’t perform that action at this time.
0 commit comments