Class the starts a subprocess and keeps it around to communicate with it via stdin. For each instruction send over stdin, a response is read and returned. The response structure is determined by “output_proc”
- class datalad.cmd.BatchedCommand(cmd: str | Tuple | List, path: str | None = None, output_proc: Callable | None = None, timeout: float | None = None, exception_on_timeout: bool = False)¶
Container for a running subprocess. Supports communication with the subprocess via stdin and stdout.
- classmethod clean_inactive()¶
Close communication and wait for process to terminate. If the “timeout” parameter to the constructor was not None, and if the configuration setting “datalad.runtime.stalled-external” is set to “abandon”, the method will return latest after “timeout” seconds. If the subprocess did not exit within this time, the attribute “wait_timed_out” will be set to “True”.
return_stderr (bool) – if set to “True”, the call will return all collected stderr content as string. In addition, if return_stderr is True and the log level is 5 or lower, and the configuration setting “datalad.log.outputs” evaluates to “True”, the content of stderr will be logged.
stderr output if return_stderr is True, None otherwise
- Return type:
- get_one_line() str | None ¶
Get a single stdout line from the generator.
If timeout was specified, and exception_on_timeout is False, and if a timeout occurs, return None. Otherwise, return the string that was read from the generator.
- get_requested_error_output(return_stderr: bool)¶
- get_timeout_exception(fd: int | None) TimeoutExpired | None ¶
Get a process timeout exception if timeout exceptions should be generated for a process that continues longer than timeout seconds after self.close() was initiated.
- proc1(single_command: str)¶
Simulate the old interface. This method is used only once in AnnexRepo.get_metadata()
- process_request(request: Tuple | str) Any | None ¶
- process_running() bool ¶
- exception datalad.cmd.BatchedCommandError(cmd='', last_processed_request='', msg='', code=None, stdout='', stderr='', cwd=None, **kwargs)¶
- class datalad.cmd.BatchedCommandProtocol(batched_command: BatchedCommand, done_future: Any | None = None, encoding: str | None = None, output_proc: Callable | None = None)¶
- pipe_connection_lost(fd: int, exc: Exception | None)¶
Called when a file descriptor associated with the child process is closed.
fd is the int file descriptor that was closed.
- pipe_data_received(fd: int, data: bytes)¶
- timeout(fd: int | None) bool ¶
Called if the timeout parameter to WitlessRunner.run() is not None and a process file descriptor could not be read (stdout or stderr) or not be written (stdin) within the specified time in seconds, or if waiting for a subprocess to exit takes longer than the specified time.
stdin timeouts are only caught when the type of the stdin- parameter to WitlessRunner.run() is either a Queue, a str, or bytes. Stdout or stderr timeouts are only caught of proc_out and proc_err are True in the protocol class. Process wait timeouts are always caught if timeout is not None. In this case the fd-argument will be None.
The file descriptor that timed out or None if no progress was made at all, i.e. no stdin element was enqueued and no output was read from either stdout or stderr.
If the callback returns True, the file descriptor (if any was given) will be closed and no longer monitored. If the return values is anything else than True, the file-descriptor will be monitored further and additional timeouts might occur indefinitely. If None was given, i.e. a process runtime-timeout was detected, and True is returned, the process will be terminated.
- class datalad.cmd.ReadlineEmulator(batched_command: BatchedCommand)¶
This class implements readline() on the basis of an instance of BatchedCommand. Its purpose is to emulate stdout’s for output_procs, This allows us to provide a BatchedCommand API that is identical to the old version, but with an implementation that is based on the threaded runner.
Read from the stdout provider until we have a line or None (which indicates some error).
- class datalad.cmd.SafeDelCloseMixin¶
A helper class to use where __del__ would call .close() which might fail if “too late in GC game”