agronholm / anyio

High level asynchronous concurrency and networking framework that works on top of either trio or asyncio
MIT License
1.74k stars 135 forks source link

Allow passing kwargs to anyio.open_process and anyio.run_process #742

Closed dolamroth closed 6 days ago

dolamroth commented 3 months ago

Things to check first

Feature description

Accept **kwargs in anyio.run_process and anyio.open_process and pass those to underlying asyncio.create_subprocess_exec, asyncio.create_subprocess_shell or trio._subprocess.open_process

Use case

subprocess.Popen allows to pass a number of kwargs to manage process behavior (most of which are OS-dependent)

def __init__(self, args, bufsize=-1, executable=None,
                 stdin=None, stdout=None, stderr=None,
                 preexec_fn=None, close_fds=True,
                 shell=False, cwd=None, env=None, universal_newlines=None,
                 startupinfo=None, creationflags=0,
                 restore_signals=True, start_new_session=False,
                 pass_fds=(), *, user=None, group=None, extra_groups=None,
                 encoding=None, errors=None, text=None, umask=-1, pipesize=-1,
                 process_group=None):

Currently it seems not possible to pass most of these to anyio's wrappers anyio.open_process and anyio.run_process, but it would be beneficial to have.

agronholm commented 3 months ago

I'd rather add these options explicitly rather than allow passing **kwargs, for type safety reasons.

agronholm commented 3 months ago

Also, not all options may work well in an async environment so I have to consider each one separately.