patroni.postgresql.cancellable module¶
-
class
patroni.postgresql.cancellable.CancellableExecutor¶ Bases:
objectThere must be only one such process so that AsyncExecutor can easily cancel it.
-
__init__() → None¶ Initialize self. See help(type(self)) for accurate signature.
-
_kill_children() → None¶
-
_kill_process() → None¶
-
_start_process(cmd: List[str], *args: Any, **kwargs: Any) → Optional[bool]¶ This method must be executed only when the _lock is acquired
-
-
class
patroni.postgresql.cancellable.CancellableSubprocess¶ Bases:
patroni.postgresql.cancellable.CancellableExecutor-
__init__() → None¶ Initialize self. See help(type(self)) for accurate signature.
-
_communicate_streaming(stream_cb: Callable[[str, bytes], None]) → Tuple[bytes, bytes]¶ Read the running process’ stdout/stderr line-by-line as it arrives.
stderris drained by a single helper thread whilestdoutis read inline, so both pipes are drained concurrently with only one extra thread.read1()returns as soon as any data is available, so slowly produced lines are delivered promptly. Lines are split on LF, CRLF, or a bare CR, so that progress reports of oldpg_basebackup/pg_rewindversions are streamed as well. Exceptions fromstream_cbare swallowed so streaming continues; only read/OS errors abort (after both streams are drained).- Parameters
stream_cb – called as
stream_cb(stream_name, line)for every complete line of stdout/stderr.- Returns
(stdout_bytes, stderr_bytes).
-
call(*args: Any, **kwargs: Any) → Optional[int]¶ Start a cancellable subprocess, optionally capture/stream its output, and wait for it to finish.
Positional and keyword arguments are forwarded to
psutil.Popen, except for the two special keyword arguments below, which are consumed here.- Parameters
communicate – optional
dictused to exchange data with the process. When provided, stdout and stderr are captured and stored back into it under thestdoutandstderrkeys, and an optionalinputvalue is sent to stdin.stream_cb – optional callback invoked as
stream_cb(stream_name, line)for every complete line of stdout/stderr as it arrives. Effective only when there is noinputto send; forces binary pipes.
- Raises
PostgresException – if the executor was already cancelled.
- Returns
the process’ exit code, or
Noneif it could not be started.
-
cancel(kill: bool = False) → None¶
-
property
is_cancelled¶
-
reset_is_cancelled() → None¶
-