File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
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
3536_logger = logging .getLogger (__name__ )
3637
3738
39+ def _shutdown_pool_at_exit () -> None :
40+ """Best-effort shutdown of the global ProcessPoolExecutor on interpreter exit."""
41+ global _pool
42+ with _pool_lock :
43+ if _pool is not None :
44+ try :
45+ _pool .shutdown (cancel_futures = True )
46+ except Exception :
47+ _logger .debug (
48+ "Error during ProcessPoolExecutor shutdown at exit" ,
49+ exc_info = True ,
50+ )
51+ finally :
52+ _pool = None
53+
54+
55+ atexit .register (_shutdown_pool_at_exit )
56+
57+
3858def _get_pool () -> ProcessPoolExecutor :
3959 global _pool
4060 with _pool_lock :
You can’t perform that action at this time.
0 commit comments