Skip to content

Commit c492344

Browse files
authored
Start kdist workers with spawn (#4601)
* Ensure that the start method is the same on all platforms (https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods) * Set the log level in the worker. This fixes an issue on macOS where the worker logs are not visible.
1 parent dcecc3d commit c492344

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pyk/src/pyk/kdist/__main__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99
from pyk.cli.utils import loglevel
1010

1111
from ..kdist import kdist, target_ids
12+
from .utils import LOG_FORMAT
1213

1314
if TYPE_CHECKING:
1415
from argparse import Namespace
1516
from typing import Final
1617

1718

1819
_LOGGER: Final = logging.getLogger(__name__)
19-
_LOG_FORMAT: Final = '%(levelname)s %(asctime)s %(name)s - %(message)s'
2020

2121

2222
def main() -> None:
2323
args = _parse_arguments()
24+
log_level = loglevel(args)
2425

25-
logging.basicConfig(level=loglevel(args), format=_LOG_FORMAT)
26+
logging.basicConfig(level=log_level, format=LOG_FORMAT)
2627

2728
if args.command == 'build':
28-
_exec_build(**vars(args))
29+
_exec_build(log_level=log_level, **vars(args))
2930

3031
elif args.command == 'clean':
3132
_exec_clean(args.target)
@@ -45,6 +46,7 @@ def _exec_build(
4546
targets: list[str],
4647
args: list[str],
4748
jobs: int,
49+
log_level: int,
4850
force: bool,
4951
verbose: bool,
5052
debug: bool,
@@ -54,6 +56,7 @@ def _exec_build(
5456
target_ids=_process_targets(targets),
5557
args=_process_args(args),
5658
jobs=jobs,
59+
log_level=log_level,
5760
force=force,
5861
verbose=verbose or debug,
5962
clean=clean,

pyk/src/pyk/kdist/_kdist.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import concurrent.futures
44
import json
55
import logging
6+
import multiprocessing
67
import os
78
import shutil
89
from concurrent.futures import ProcessPoolExecutor
@@ -20,6 +21,7 @@
2021
from . import utils
2122
from ._cache import target_cache
2223
from .api import TargetId
24+
from .utils import LOG_FORMAT
2325

2426
if TYPE_CHECKING:
2527
from collections.abc import Iterable, Iterator, Mapping
@@ -84,6 +86,7 @@ def build(
8486
*,
8587
args: Mapping[str, str] | None = None,
8688
jobs: int = 1,
89+
log_level: int = logging.WARNING,
8790
force: bool = False,
8891
verbose: bool = False,
8992
clean: bool = True,
@@ -99,14 +102,15 @@ def build(
99102
deps_fqns = [target_id.full_name for target_id in dep_ids]
100103
_LOGGER.info(f"Building targets: {', '.join(deps_fqns)}")
101104

102-
with ProcessPoolExecutor(max_workers=jobs) as pool:
105+
with ProcessPoolExecutor(max_workers=jobs, mp_context=multiprocessing.get_context('spawn')) as pool:
103106
pending: dict[Future[Path], TargetId] = {}
104107

105108
def submit(target_id: TargetId) -> None:
106109
future = pool.submit(
107110
self._build_target,
108111
target_id=target_id,
109112
args=args,
113+
log_level=log_level,
110114
force=force,
111115
verbose=verbose,
112116
clean=clean,
@@ -134,10 +138,13 @@ def _build_target(
134138
target_id: TargetId,
135139
args: dict[str, Any],
136140
*,
141+
log_level: int,
137142
force: bool,
138143
verbose: bool,
139144
clean: bool,
140145
) -> Path:
146+
logging.basicConfig(level=log_level, format=LOG_FORMAT)
147+
141148
target = target_cache().resolve(target_id)
142149
output_dir = self._target_dir(target_id)
143150
manifest_file = self._manifest_file(target_id)

pyk/src/pyk/kdist/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
if TYPE_CHECKING:
1212
from collections.abc import Iterator
13-
from typing import Any
13+
from typing import Any, Final
14+
15+
16+
LOG_FORMAT: Final = '%(levelname)s %(asctime)s %(name)s - %(message)s'
1417

1518

1619
def package_path(obj: Any) -> Path:

0 commit comments

Comments
 (0)