Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start kdist workers with spawn #4601

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pyk/src/pyk/kdist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@
from pyk.cli.utils import loglevel

from ..kdist import kdist, target_ids
from .utils import LOG_FORMAT

if TYPE_CHECKING:
from argparse import Namespace
from typing import Final


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


def main() -> None:
args = _parse_arguments()
log_level = loglevel(args)

logging.basicConfig(level=loglevel(args), format=_LOG_FORMAT)
logging.basicConfig(level=log_level, format=LOG_FORMAT)

if args.command == 'build':
_exec_build(**vars(args))
_exec_build(log_level=log_level, **vars(args))

elif args.command == 'clean':
_exec_clean(args.target)
Expand All @@ -45,6 +46,7 @@ def _exec_build(
targets: list[str],
args: list[str],
jobs: int,
log_level: int,
force: bool,
verbose: bool,
debug: bool,
Expand All @@ -54,6 +56,7 @@ def _exec_build(
target_ids=_process_targets(targets),
args=_process_args(args),
jobs=jobs,
log_level=log_level,
force=force,
verbose=verbose or debug,
clean=clean,
Expand Down
9 changes: 8 additions & 1 deletion pyk/src/pyk/kdist/_kdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import concurrent.futures
import json
import logging
import multiprocessing
import os
import shutil
from concurrent.futures import ProcessPoolExecutor
Expand All @@ -20,6 +21,7 @@
from . import utils
from ._cache import target_cache
from .api import TargetId
from .utils import LOG_FORMAT

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Mapping
Expand Down Expand Up @@ -84,6 +86,7 @@ def build(
*,
args: Mapping[str, str] | None = None,
jobs: int = 1,
log_level: int = logging.WARNING,
force: bool = False,
verbose: bool = False,
clean: bool = True,
Expand All @@ -99,14 +102,15 @@ def build(
deps_fqns = [target_id.full_name for target_id in dep_ids]
_LOGGER.info(f"Building targets: {', '.join(deps_fqns)}")

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

def submit(target_id: TargetId) -> None:
future = pool.submit(
self._build_target,
target_id=target_id,
args=args,
log_level=log_level,
force=force,
verbose=verbose,
clean=clean,
Expand Down Expand Up @@ -134,10 +138,13 @@ def _build_target(
target_id: TargetId,
args: dict[str, Any],
*,
log_level: int,
force: bool,
verbose: bool,
clean: bool,
) -> Path:
logging.basicConfig(level=log_level, format=LOG_FORMAT)
tothtamas28 marked this conversation as resolved.
Show resolved Hide resolved

target = target_cache().resolve(target_id)
output_dir = self._target_dir(target_id)
manifest_file = self._manifest_file(target_id)
Expand Down
5 changes: 4 additions & 1 deletion pyk/src/pyk/kdist/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

if TYPE_CHECKING:
from collections.abc import Iterator
from typing import Any
from typing import Any, Final


LOG_FORMAT: Final = '%(levelname)s %(asctime)s %(name)s - %(message)s'


def package_path(obj: Any) -> Path:
Expand Down
Loading