Skip to content

Commit 3c17f76

Browse files
committed
Kill individual worker process after timeout in test_build_meta
According to the Python docs, shutting down the process pool does not terminate the tasks that are already running, so it is necessary to manually kill the individual processes in the pool.
1 parent 0504b5c commit 3c17f76

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

setuptools/tests/test_build_meta.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22
import shutil
3+
import signal
34
import tarfile
45
import importlib
6+
import contextlib
57
from concurrent import futures
68
import re
79

@@ -34,15 +36,23 @@ def __getattr__(self, name):
3436
def method(*args, **kw):
3537
root = os.path.abspath(self.cwd)
3638
caller = BuildBackendCaller(root, self.env, self.backend_name)
37-
task = self.pool.submit(caller, name, *args, **kw)
39+
pid = None
3840
try:
39-
return task.result(TIMEOUT)
41+
pid = self.pool.submit(os.getpid).result(TIMEOUT)
42+
return self.pool.submit(caller, name, *args, **kw).result(TIMEOUT)
4043
except futures.TimeoutError:
41-
self.pool.shutdown(wait=False)
44+
self.pool.shutdown(wait=False) # doesn't stop already running processes
45+
self._kill(pid)
4246
pytest.xfail(f"Backend did not respond before timeout ({TIMEOUT} s)")
4347

4448
return method
4549

50+
def _kill(self, pid):
51+
if pid is None:
52+
return
53+
with contextlib.suppress(ProcessLookupError):
54+
os.kill(pid, signal.SIGKILL)
55+
4656

4757
class BuildBackendCaller(BuildBackendBase):
4858
def __init__(self, *args, **kwargs):

0 commit comments

Comments
 (0)