Skip to content

Commit 35e9e24

Browse files
committed
fix: ignore SIGINT during shutting down the pool
1 parent 633cc2e commit 35e9e24

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

python/cocoindex/subprocess_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def shutdown_pool_at_exit() -> None:
4545
if _pool is not None:
4646
try:
4747
print("Before shutdown")
48-
_pool.shutdown(cancel_futures=True)
48+
_pool.shutdown(wait=True, cancel_futures=True)
4949
print("After shutdown")
5050
except Exception as e:
5151
_logger.error(

python/cocoindex/tests/conftest.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import pytest
22
import typing
3+
import os
4+
import signal
35

46

57
@pytest.fixture(scope="session", autouse=True)
68
def _cocoindex_env_fixture() -> typing.Generator[None, None, None]:
79
"""Shutdown the subprocess pool at exit."""
10+
811
yield
12+
913
try:
1014
print("Shutdown the subprocess pool at exit in hook.")
1115
import cocoindex.subprocess_exec
1216

13-
cocoindex.subprocess_exec.shutdown_pool_at_exit()
14-
except Exception:
17+
if os.name == "nt":
18+
original_sigint_handler = signal.getsignal(signal.SIGINT)
19+
try:
20+
signal.signal(signal.SIGINT, signal.SIG_IGN)
21+
cocoindex.subprocess_exec.shutdown_pool_at_exit()
22+
finally:
23+
try:
24+
signal.signal(signal.SIGINT, original_sigint_handler)
25+
except ValueError: # noqa: BLE001
26+
pass
27+
else:
28+
cocoindex.subprocess_exec.shutdown_pool_at_exit()
29+
except (ImportError, AttributeError): # noqa: BLE001
1530
pass

0 commit comments

Comments
 (0)