Skip to content

Commit bfddd21

Browse files
committed
fix: explicitly shutdown in pytest fixture
1 parent 8118636 commit bfddd21

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

python/cocoindex/subprocess_exec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
_logger = logging.getLogger(__name__)
3838

3939

40-
def _shutdown_pool_at_exit() -> None:
40+
def shutdown_pool_at_exit() -> None:
4141
"""Best-effort shutdown of the global ProcessPoolExecutor on interpreter exit."""
4242
global _pool, _pool_cleanup_registered # pylint: disable=global-statement
4343
print("Shutting down pool at exit")
@@ -65,7 +65,7 @@ def _get_pool() -> ProcessPoolExecutor:
6565
if not _pool_cleanup_registered:
6666
# Register the shutdown at exit at creation time (rather than at import time)
6767
# to make sure it's executed earlier in the shutdown sequence.
68-
atexit.register(_shutdown_pool_at_exit)
68+
atexit.register(shutdown_pool_at_exit)
6969
_pool_cleanup_registered = True
7070

7171
# Single worker process as requested

python/cocoindex/tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
import typing
3+
4+
5+
@pytest.fixture(scope="session", autouse=True)
6+
def _cocoindex_env_fixture() -> typing.Generator[None, None, None]:
7+
"""Shutdown the subprocess pool at exit."""
8+
yield
9+
try:
10+
print("Shutdown the subprocess pool at exit in hook.")
11+
import cocoindex.subprocess_exec
12+
13+
cocoindex.subprocess_exec.shutdown_pool_at_exit()
14+
except Exception:
15+
pass

0 commit comments

Comments
 (0)