sc3nb.process_handling
Module for process handling.
Module Contents
Function List
Looks for executable in os $PATH or specified path |
|
Kill processes with the same path for the executable. |
Class List
Class for starting a executable and communication with it. |
Content
- sc3nb.process_handling.find_executable(executable: str, search_path: str = None, add_to_path: bool = False)[source]
Looks for executable in os $PATH or specified path
- Parameters:
- executablestr
Executable to be found
- search_pathstr, optional
Path at which to look for, by default None
- add_to_pathbool, optional
Wether to add the provided path to os $PATH or not, by default False
- Returns:
- str
Full path to executable
- Raises:
- FileNotFoundError
Raised if executable cannot be found
- sc3nb.process_handling.kill_processes(exec_path, allowed_parents: Optional[tuple] = None)[source]
Kill processes with the same path for the executable.
If allowed_parent is provided it will be searched in the names of the parent processes of the process with the executable path before terminating. If it is found the process won’t be killed.
- Parameters:
- exec_pathstr
path of the executable to kill
- allowed_parentstr, optional
parents name of processes to keep, by default None
- exception sc3nb.process_handling.ProcessTimeout(executable, output, timeout, expected)[source]
Bases:
Exception
Process Timeout Exception
Initialize self. See help(type(self)) for accurate signature.
- class sc3nb.process_handling.Process(executable: str, programm_args: Optional[Sequence[str]] = None, executable_path: str = None, console_logging: bool = True, kill_others: bool = True, allowed_parents: Sequence[str] = None)[source]
Class for starting a executable and communication with it.
- Parameters:
- executablestr
Name of executable to start
- programm_argsOptional[Sequence[str]], optional
Arguments to program start with Popen, by default None
- executable_pathstr, optional
Path with executalbe, by default system PATH
- console_loggingbool, optional
Flag for controlling console logging, by default True
- kill_othersbool, optional
Flag for controlling killing of other executables with the same name. This is useful when processes where left over, by default True
- allowed_parentsSequence[str], optional
Sequence of parent names that won’t be killed when kill_others is True, by default None
Overview:
Reads current output from output queue until expect is found
Empties output queue.
Send input to process
Kill the process.
Return repr(self).
- read(expect: Optional[str] = None, timeout: float = 3) str [source]
Reads current output from output queue until expect is found
- Parameters:
- expectstr, optional
str that we expect to find, by default None
- timeoutfloat, optional
timeout in seconds for waiting for output, by default 3
- Returns:
- str
Output of process.
- Raises:
- ProcessTimeout
If neither output nor expect is found