processes
Class info¶
🛈 DocStrings¶
Process ceation utilities.
create_process
async
¶
create_process(
command: str | PathLike[str],
*args: str | PathLike[str],
stdin: Mode | None = None,
stdout: Mode | None = None,
stderr: Mode | None = None,
limit: int = 10 * 1024 * 1024,
env: dict[str, str] | None = None,
cwd: str | PathLike[str] | None = None,
start_new_session: bool = False,
) -> Process
Small create_subprocess_exec wrapper.
Source code in src/anyenv/processes.py
create_shell_process
async
¶
create_shell_process(
command: str,
stdin: Mode | None = None,
stdout: Mode | None = None,
stderr: Mode | None = None,
limit: int = 10 * 1024 * 1024,
cwd: str | PathLike[str] | None = None,
env: dict[str, str] | None = None,
start_new_session: bool = False,
) -> Process
Small create_subprocess_shell wrapper.
Source code in src/anyenv/processes.py
hard_kill
async
¶
Kill a process with graceful termination followed by force kill if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
Process
|
The subprocess to terminate |
required |
graceful_timeout
|
float
|
Timeout for graceful termination (default: 5.0s) |
5.0
|
force_timeout
|
float
|
Timeout for force kill (default: 2.0s) |
2.0
|
This function handles cross-platform process termination:
- Windows: Uses terminate() then kill() as fallback
- Unix: SIGTERM, then SIGKILL after graceful_timeout. When the process leads
its own process group (started with start_new_session=True), the signals go
to the whole group, so its children die too; they get the whole
graceful_timeout even when the leader exits first. Otherwise only the process itself
is signalled: its group is the caller's own.