Original code copyright (C) 2009-2022 Rudolf Cardinal (email@example.com).
This file is part of cardinal_pythonlib.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Support functions for process/external command management.
get_external_command_output(command: str) → bytes¶
Takes a command-line command, executes it, and returns its
Parameters: command – command string Returns: output from the command as
get_pipe_series_output(commands: Sequence[str], stdinput: BinaryIO = None) → bytes¶
Get the output from a piped series of commands.
- commands – sequence of command strings
- stdinput – optional
stdindata to feed into the start of the pipe
stdoutfrom the end of the pipe
kill_proc_tree(pid: int, including_parent: bool = True, timeout_s: float = 5) → Tuple[Set[psutil.Process], Set[psutil.Process]]¶
Kills a tree of processes, starting with the parent. Slightly modified from https://stackoverflow.com/questions/1230669/subprocess-deleting-child-processes-in-windows.
- pid – process ID of the parent
- including_parent – kill the parent too?
- timeout_s – timeout to wait for processes to close
(gone, still_alive), where both are sets of
launch_external_file(filename: str, raise_if_fails: bool = False) → None¶
Launches a file using the operating system’s standard launcher.
- filename – file to launch
- raise_if_fails – raise any exceptions from
subprocess.call(["xdg-open", filename])(Linux) or
os.startfile(filename)(otherwise)? If not, exceptions are suppressed.
nice_call(*popenargs, timeout: float = None, cleanup_timeout: float = None, **kwargs) → int¶
subprocess.call(), but give the child process time to clean up and communicate if a