All checks were successful
buildbot/nix-build .#checks.x86_64-linux.clan-dep-e2fsprogs Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-bash Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-no-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-fakeroot Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-age Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.check-for-breakpoints Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-app-pytest Build done.
buildbot/nix-build .#checks.x86_64-linux.borgbackup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-darwin.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.aarch64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-git Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-openssh Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-mypy" Build done.
buildbot/nix-build .#checks.x86_64-linux."clan-dep-python3.11-qemu" Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-rsync Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sops Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-sshpass Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-zbar Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-without-core Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-pytest-with-core Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.deltachat Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-default Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test_install_machine Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-tor Build done.
buildbot/nix-build .#checks.x86_64-linux.devShell-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.clan-dep-nix Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-example-valid Build done.
buildbot/nix-build .#checks.x86_64-linux.container Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-app Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-cli-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-clan-ts-api Build done.
buildbot/nix-build .#checks.x86_64-linux.package-default Build done.
buildbot/nix-build .#checks.x86_64-linux.matrix-synapse Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-install-test-ubuntu-22-04 Build done.
buildbot/nix-build .#checks.x86_64-linux.test-backups Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-apk Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-deb Build done.
buildbot/nix-build .#checks.x86_64-linux.module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-editor Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-archlinux Build done.
buildbot/nix-build .#checks.x86_64-linux.package-gui-installer-rpm Build done.
buildbot/nix-build .#checks.x86_64-linux.package-impure-checks Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-test-backup Build done.
buildbot/nix-build .#checks.x86_64-linux.lib-jsonschema-nix-unit-tests Build done.
buildbot/nix-build .#checks.x86_64-linux.package-deploy-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.package-moonlight-sunshine-accept Build done.
buildbot/nix-build .#checks.x86_64-linux.package-pending-reviews Build done.
buildbot/nix-build .#checks.x86_64-linux.package-tea-create-pr Build done.
buildbot/nix-build .#checks.x86_64-linux.package-webview-ui Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotier-members Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zerotierone Build done.
buildbot/nix-build .#checks.x86_64-linux.package-zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.nixos-flash-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.secrets Build done.
buildbot/nix-build .#checks.x86_64-linux.treefmt Build done.
buildbot/nix-build .#checks.x86_64-linux.package-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.renderClanOptions Build done.
buildbot/nix-build .#checks.x86_64-linux.package-function-schema Build done.
buildbot/nix-build .#checks.x86_64-linux.package-merge-after-ci Build done.
buildbot/nix-build .#checks.x86_64-linux.package-module-docs Build done.
buildbot/nix-build .#checks.x86_64-linux.wayland-proxy-virtwl Build done.
buildbot/nix-build .#checks.x86_64-linux.zt-tcp-relay Build done.
buildbot/nix-build .#checks.x86_64-linux.package-iso-installer Build done.
buildbot/nix-build .#checks.x86_64-linux.syncthing Build done.
checks / checks-impure (pull_request) Successful in 2m19s
buildbot/nix-build .#checks.x86_64-linux.flash Build done.
buildbot/nix-build .#checks.x86_64-linux.test-installation Build done.
buildbot/nix-eval Build done.
133 lines
3.3 KiB
Python
133 lines
3.3 KiB
Python
import logging
|
|
import os
|
|
import signal
|
|
import sys
|
|
import traceback
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import gi
|
|
|
|
gi.require_version("GdkPixbuf", "2.0")
|
|
|
|
import dataclasses
|
|
import multiprocessing as mp
|
|
from collections.abc import Callable
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
# Kill the new process and all its children by sending a SIGTERM signal to the process group
|
|
def _kill_group(proc: mp.Process) -> None:
|
|
pid = proc.pid
|
|
if proc.is_alive() and pid:
|
|
os.killpg(pid, signal.SIGTERM)
|
|
else:
|
|
log.warning(f"Process '{proc.name}' with pid '{pid}' is already dead")
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class MPProcess:
|
|
name: str
|
|
proc: mp.Process
|
|
out_file: Path
|
|
|
|
# Kill the new process and all its children by sending a SIGTERM signal to the process group
|
|
def kill_group(self) -> None:
|
|
_kill_group(proc=self.proc)
|
|
|
|
|
|
def _set_proc_name(name: str) -> None:
|
|
if sys.platform != "linux":
|
|
return
|
|
import ctypes
|
|
|
|
# Define the prctl function with the appropriate arguments and return type
|
|
libc = ctypes.CDLL("libc.so.6")
|
|
prctl = libc.prctl
|
|
prctl.argtypes = [
|
|
ctypes.c_int,
|
|
ctypes.c_char_p,
|
|
ctypes.c_ulong,
|
|
ctypes.c_ulong,
|
|
ctypes.c_ulong,
|
|
]
|
|
prctl.restype = ctypes.c_int
|
|
|
|
# Set the process name to "my_process"
|
|
prctl(15, name.encode(), 0, 0, 0)
|
|
|
|
|
|
def _init_proc(
|
|
func: Callable,
|
|
out_file: Path,
|
|
proc_name: str,
|
|
on_except: Callable[[Exception, mp.process.BaseProcess], None] | None,
|
|
**kwargs: Any,
|
|
) -> None:
|
|
# Create a new process group
|
|
os.setsid()
|
|
|
|
# Open stdout and stderr
|
|
with open(out_file, "w") as out_fd:
|
|
os.dup2(out_fd.fileno(), sys.stdout.fileno())
|
|
os.dup2(out_fd.fileno(), sys.stderr.fileno())
|
|
|
|
# Print some information
|
|
pid = os.getpid()
|
|
gpid = os.getpgid(pid=pid)
|
|
|
|
# Set the process name
|
|
_set_proc_name(proc_name)
|
|
|
|
# Close stdin
|
|
sys.stdin.close()
|
|
|
|
linebreak = "=" * 5
|
|
# Execute the main function
|
|
print(linebreak + f" {func.__name__}:{pid} " + linebreak, file=sys.stderr)
|
|
try:
|
|
func(**kwargs)
|
|
except Exception as ex:
|
|
traceback.print_exc()
|
|
if on_except is not None:
|
|
on_except(ex, mp.current_process())
|
|
|
|
# Kill the new process and all its children by sending a SIGTERM signal to the process group
|
|
pid = os.getpid()
|
|
gpid = os.getpgid(pid=pid)
|
|
print(f"Killing process group pid={pid} gpid={gpid}", file=sys.stderr)
|
|
os.killpg(gpid, signal.SIGTERM)
|
|
sys.exit(1)
|
|
# Don't use a finally block here, because we want the exitcode to be set to
|
|
# 0 if the function returns normally
|
|
|
|
|
|
def spawn(
|
|
*,
|
|
out_file: Path,
|
|
on_except: Callable[[Exception, mp.process.BaseProcess], None] | None,
|
|
func: Callable,
|
|
**kwargs: Any,
|
|
) -> MPProcess:
|
|
# Decouple the process from the parent
|
|
if mp.get_start_method(allow_none=True) is None:
|
|
mp.set_start_method(method="forkserver")
|
|
|
|
# Set names
|
|
proc_name = f"MPExec:{func.__name__}"
|
|
|
|
# Start the process
|
|
proc = mp.Process(
|
|
target=_init_proc,
|
|
args=(func, out_file, proc_name, on_except),
|
|
name=proc_name,
|
|
kwargs=kwargs,
|
|
)
|
|
proc.start()
|
|
|
|
# Return the process
|
|
mp_proc = MPProcess(name=proc_name, proc=proc, out_file=out_file)
|
|
|
|
return mp_proc
|