diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3906d9b5..cd5afb03 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,4 @@ +- Change to process group for better killing of multi-process chrome - Add argument to Session/Target send_command with_perf to return timing information about browser write/read. - Update default chrome from 135.0.7011.0/1418433 to 144.0.7527.0/1544685 diff --git a/src/choreographer/browser_async.py b/src/choreographer/browser_async.py index 8c141ed9..0a421367 100644 --- a/src/choreographer/browser_async.py +++ b/src/choreographer/browser_async.py @@ -1,5 +1,7 @@ """Provides the async api: `Browser`, `Tab`.""" +# hello, thank you for visiting + from __future__ import annotations import asyncio diff --git a/src/choreographer/browsers/chromium.py b/src/choreographer/browsers/chromium.py index 447b3b1d..d3ff25e6 100644 --- a/src/choreographer/browsers/chromium.py +++ b/src/choreographer/browsers/chromium.py @@ -204,6 +204,8 @@ def get_popen_args(self) -> Mapping[str, Any]: if isinstance(self._channel, Pipe): args["stdin"] = self._channel.from_choreo_to_external args["stdout"] = self._channel.from_external_to_choreo + args["start_new_session"] = True + _logger.debug(f"Returning args: {args}") return args diff --git a/src/choreographer/utils/_kill.py b/src/choreographer/utils/_kill.py index 17d4cfc7..67512d5b 100644 --- a/src/choreographer/utils/_kill.py +++ b/src/choreographer/utils/_kill.py @@ -1,26 +1,43 @@ from __future__ import annotations +import os import platform import subprocess import logistro +if (_system := platform.system()) != "Windows": + import signal + _logger = logistro.getLogger(__name__) def kill(process: subprocess.Popen[bytes] | subprocess.Popen[str]) -> None: - if platform.system() == "Windows": + if _system == "Windows": subprocess.call( # noqa: S603, false positive, input fine ["taskkill", "/F", "/T", "/PID", str(process.pid)], # noqa: S607 windows full path... stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL, timeout=6, ) - else: + return + + try: + os.killpg( + process.pid, + signal.SIGTERM, # type: ignore[reportPossiblyUnboundVariable] + ) + except ProcessLookupError: process.terminate() - _logger.debug("Called terminate (a light kill).") + _logger.debug("Called terminate (a light kill).") + try: + process.wait(timeout=6) + except subprocess.TimeoutExpired: + _logger.debug("Calling kill (a heavy kill).") try: - process.wait(timeout=6) - except subprocess.TimeoutExpired: - _logger.debug("Calling kill (a heavy kill).") + os.killpg( + process.pid, + signal.SIGKILL, # type: ignore[reportPossiblyUnboundVariable] + ) + except ProcessLookupError: process.kill()