• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pyiron / executorlib / 11907763573

19 Nov 2024 06:52AM UTC coverage: 95.648%. Remained the same
11907763573

push

github

web-flow
[pre-commit.ci] pre-commit autoupdate (#502)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4)

* Update environment-openmpi.yml

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jan Janssen <jan-janssen@users.noreply.github.com>

945 of 988 relevant lines covered (95.65%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/executorlib/cache/subprocess_spawner.py
1
import subprocess
1✔
2
import time
1✔
3
from typing import Optional
1✔
4

5
from executorlib.standalone.inputcheck import check_file_exists
1✔
6

7

8
def execute_in_subprocess(
1✔
9
    command: list,
10
    task_dependent_lst: list = [],
11
    file_name: Optional[str] = None,
12
    resource_dict: Optional[dict] = None,
13
    config_directory: Optional[str] = None,
14
    backend: Optional[str] = None,
15
    cache_directory: Optional[str] = None,
16
) -> subprocess.Popen:
17
    """
18
    Execute a command in a subprocess.
19

20
    Args:
21
        command (list): The command to be executed.
22
        task_dependent_lst (list): A list of subprocesses that the current subprocess depends on. Defaults to [].
23
        file_name (str): Name of the HDF5 file which contains the Python function
24
        resource_dict (dict): resource dictionary, which defines the resources used for the execution of the function.
25
                              Example resource dictionary: {
26
                                  cwd: None,
27
                              }
28
        config_directory (str, optional): path to the config directory.
29
        backend (str, optional): name of the backend used to spawn tasks.
30
        cache_directory (str): The directory to store the HDF5 files.
31

32
    Returns:
33
        subprocess.Popen: The subprocess object.
34

35
    """
36
    check_file_exists(file_name=file_name)
1✔
37
    while len(task_dependent_lst) > 0:
1✔
38
        task_dependent_lst = [
1✔
39
            task for task in task_dependent_lst if task.poll() is None
40
        ]
41
    if config_directory is not None:
1✔
42
        raise ValueError(
1✔
43
            "config_directory parameter is not supported for subprocess spawner."
44
        )
45
    if backend is not None:
1✔
46
        raise ValueError("backend parameter is not supported for subprocess spawner.")
1✔
47
    if resource_dict is None:
1✔
48
        resource_dict = {}
×
49
    if "cwd" in resource_dict:
1✔
50
        cwd = resource_dict["cwd"]
1✔
51
    else:
52
        cwd = cache_directory
1✔
53
    return subprocess.Popen(command, universal_newlines=True, cwd=cwd)
1✔
54

55

56
def terminate_subprocess(task):
1✔
57
    """
58
    Terminate a subprocess and wait for it to complete.
59

60
    Args:
61
        task (subprocess.Popen): The subprocess.Popen instance to terminate
62
    """
63
    task.terminate()
1✔
64
    while task.poll() is None:
1✔
65
        time.sleep(0.1)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc