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

python-useful-helpers / exec-helpers / 14900591534

08 May 2025 06:58AM CUT coverage: 54.224%. Remained the same
14900591534

push

github

web-flow
Bump actions/download-artifact from 4.1.8 to 4.3.0 (#159)

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4.1.8 to 4.3.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v4.1.8...v4.3.0)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 4.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

98 of 201 branches covered (48.76%)

Branch coverage included in aggregate %.

1083 of 1977 relevant lines covered (54.78%)

5.48 hits per line

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

0.0
/exec_helpers/_subprocess_helpers.py
1
#    Copyright 2018 - 2023 Aleksei Stepanov aka penguinolog.
2

3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
#    not use this file except in compliance with the License. You may obtain
5
#    a copy of the License at
6

7
#         http://www.apache.org/licenses/LICENSE-2.0
8

9
#    Unless required by applicable law or agreed to in writing, software
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
#    License for the specific language governing permissions and limitations
13
#    under the License.
14

15
"""Python subprocess shared code."""
16

17
from __future__ import annotations
×
18

19
import contextlib
×
20
import platform
×
21
import typing
×
22

23
import psutil
×
24

25
__all__ = ("kill_proc_tree", "subprocess_kw")
×
26

27

28
# Adopt from:
29
# https://stackoverflow.com/questions/1230669/subprocess-deleting-child-processes-in-windows
30
def kill_proc_tree(pid: int, including_parent: bool = True) -> None:  # pragma: no cover
31
    """Kill process tree.
32

33
    :param pid: PID of parent process to kill
34
    :type pid: int
35
    :param including_parent: kill also parent process
36
    :type including_parent: bool
37
    """
38

39
    def safe_stop(proc: psutil.Process, kill: bool = False) -> None:
40
        """Do not crash on already stopped process.
41

42
        :param proc: Target process.
43
        :type proc: psutil.Process
44
        :param kill: Use SIGKILL instead of SIGTERM.
45
        :type kill: bool
46
        """
47
        with contextlib.suppress(psutil.NoSuchProcess):
48
            if kill:
49
                proc.kill()
50
            proc.terminate()
51

52
    try:
53
        parent = psutil.Process(pid)
54
    except psutil.NoSuchProcess:
55
        # The process is already closed
56
        return
57
    children: list[psutil.Process] = parent.children(recursive=True)
58
    child: psutil.Process
59
    for child in children:
60
        safe_stop(child)  # SIGTERM to allow cleanup
61
    _, alive = psutil.wait_procs(children, timeout=1)
62
    for child in alive:
63
        safe_stop(child, kill=True)  # 2nd shot: SIGKILL
64
    if including_parent:
65
        safe_stop(parent)  # SIGTERM to allow cleanup
66
        _, alive = psutil.wait_procs((parent,), timeout=1)
67
        if alive:
68
            safe_stop(parent, kill=True)  # 2nd shot: SIGKILL
69
        parent.wait(5)
70

71

72
# Subprocess extra arguments.
73
# Flags from:
74
# https://stackoverflow.com/questions/13243807/popen-waiting-for-child-process-even-when-the-immediate-child-has-terminated
75
subprocess_kw: dict[str, typing.Any] = {}
×
76
if platform.system() == "Windows":
77
    subprocess_kw["creationflags"] = 0x00000200
78
else:  # pragma: no cover
79
    subprocess_kw["start_new_session"] = True
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