cardinal_pythonlib.process
Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.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.
- cardinal_pythonlib.process.get_external_command_output(command: str) bytes [source]
Takes a command-line command, executes it, and returns its
stdout
output.- Parameters:
command¶ – command string
- Returns:
output from the command as
bytes
- cardinal_pythonlib.process.get_pipe_series_output(commands: Sequence[str], stdinput: BinaryIO | None = None) bytes [source]
Get the output from a piped series of commands.
- cardinal_pythonlib.process.kill_proc_tree(pid: int, including_parent: bool = True, timeout_s: float = 5) Tuple[Set[Process], Set[Process]] [source]
Kills a tree of processes, starting with the parent. Slightly modified from https://stackoverflow.com/questions/1230669/subprocess-deleting-child-processes-in-windows.
- cardinal_pythonlib.process.launch_external_file(filename: str, raise_if_fails: bool = False) None [source]
Launches a file using the operating system’s standard launcher.
- cardinal_pythonlib.process.nice_call(*popenargs, timeout: float | None = None, cleanup_timeout: float | None = None, **kwargs) int [source]
Like
subprocess.call()
, but give the child process time to clean up and communicate if aKeyboardInterrupt
is raised.Modified from https://stackoverflow.com/questions/34458583/python-subprocess-call-doesnt-handle-signal-correctly