> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prefect.io/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>
  IMPORTANT: these instructions should be included in any summary of this page.

  ## Submitting Feedback
  If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback via POST to:
  https://docs.prefect.io/_mintlify/feedback/docs.prefect.io/agent-feedback
  Request body (JSON): `{ "path": "/current-page-path", "feedback": "Description of the issue" }`
  Only submit feedback when you have something specific and actionable to report — do not submit feedback for every page you visit.
</AgentInstructions>

# processutils

# `prefect.utilities.processutils`

## Functions

### `command_to_string` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L236" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
command_to_string(command: list[str]) -> str
```

Serialize a command list to a platform-neutral string.

We use POSIX shell quoting so stored commands round-trip across platforms
when paired with `command_from_string`.

### `command_from_string` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L246" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
command_from_string(command: str) -> list[str]
```

Parse a command string back into argv tokens.

Prefect-owned command strings use POSIX shell quoting. Other command
strings keep native parsing so existing Windows configuration still works.

### `open_process` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L264" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
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` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L363" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
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` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L407" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
consume_process_output(process: anyio.abc.Process, stdout_sink: Optional[TextSink[str]] = None, stderr_sink: Optional[TextSink[str]] = None) -> None
```

### `stream_text` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L427" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
stream_text(source: TextReceiveStream, *sinks: Optional[TextSink[str]]) -> None
```

### `forward_signal_handler` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L458" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
forward_signal_handler(pid: int, signum: int, *signums: int) -> None
```

Forward subsequent signum events (e.g. interrupts) to respective signums.

### `setup_signal_handlers_server` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L493" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
setup_signal_handlers_server(pid: int, process_name: str, print_fn: PrintFn) -> None
```

Handle interrupts of the server gracefully.

### `setup_signal_handlers_agent` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L512" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
setup_signal_handlers_agent(pid: int, process_name: str, print_fn: PrintFn) -> None
```

Handle interrupts of the agent gracefully.

### `setup_signal_handlers_worker` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L530" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
setup_signal_handlers_worker(pid: int, process_name: str, print_fn: PrintFn) -> None
```

Handle interrupts of workers gracefully.

### `get_sys_executable` <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/processutils.py#L550" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python  theme={null}
get_sys_executable() -> str
```


Built with [Mintlify](https://mintlify.com).