Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 210a141

Browse files
committedFeb 14, 2022
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 210a141

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎setuptools/tests/test_build_meta.py

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
import tarfile
44
import importlib
5+
import multiprocessing
56
from concurrent import futures
67
import re
78

@@ -39,6 +40,7 @@ def method(*args, **kw):
3940
return task.result(TIMEOUT)
4041
except futures.TimeoutError:
4142
self.pool.shutdown(wait=False)
43+
caller.shutdown() # pool.shutdown doesn't stop running processes
4244
pytest.xfail(f"Backend did not respond before timeout ({TIMEOUT} s)")
4345

4446
return method
@@ -47,12 +49,14 @@ def method(*args, **kw):
4749
class BuildBackendCaller(BuildBackendBase):
4850
def __init__(self, *args, **kwargs):
4951
super(BuildBackendCaller, self).__init__(*args, **kwargs)
52+
self._process = None
5053

5154
(self.backend_name, _,
5255
self.backend_obj) = self.backend_name.partition(':')
5356

5457
def __call__(self, name, *args, **kw):
5558
"""Handles aribrary function invocations on the build backend."""
59+
self._process = multiprocessing.current_process()
5660
os.chdir(self.cwd)
5761
os.environ.update(self.env)
5862
mod = importlib.import_module(self.backend_name)
@@ -64,6 +68,10 @@ def __call__(self, name, *args, **kw):
6468

6569
return getattr(backend, name)(*args, **kw)
6670

71+
def shutdown(self):
72+
if self._process and self._process.is_alive():
73+
self._process.kill()
74+
6775

6876
defns = [
6977
{

0 commit comments

Comments
 (0)
Please sign in to comment.