prefect.utilities.processutils

Functions

open_process

open_process(command: list[str], **kwargs: Any) -> AsyncGenerator[anyio.abc.Process, Any]
Like anyio.open_process but with:
  • Support for Windows command joining
  • Termination of the process on exception during yield
  • Forced cleanup of process resources during cancellation

run_process

run_process(command: list[str], **kwargs: Any) -> anyio.abc.Process
Like anyio.run_process but with:
  • Use of our open_process utility to ensure resources are cleaned up
  • Simple stream_output support to connect the subprocess to the parent stdout/err
  • Support for submission with TaskGroup.start marking as ‘started’ after the process has been created. When used, the PID is returned to the task status.

consume_process_output

consume_process_output(process: anyio.abc.Process, stdout_sink: Optional[TextSink[str]] = None, stderr_sink: Optional[TextSink[str]] = None) -> None

stream_text

stream_text(source: TextReceiveStream, *sinks: Optional[TextSink[str]]) -> None

forward_signal_handler

forward_signal_handler(pid: int, signum: int, *signums: int) -> None
Forward subsequent signum events (e.g. interrupts) to respective signums.

setup_signal_handlers_server

setup_signal_handlers_server(pid: int, process_name: str, print_fn: PrintFn) -> None
Handle interrupts of the server gracefully.

setup_signal_handlers_agent

setup_signal_handlers_agent(pid: int, process_name: str, print_fn: PrintFn) -> None
Handle interrupts of the agent gracefully.

setup_signal_handlers_worker

setup_signal_handlers_worker(pid: int, process_name: str, print_fn: PrintFn) -> None
Handle interrupts of workers gracefully.

get_sys_executable

get_sys_executable() -> str