MagicStack / MagicStack/uvloop

create_subprocess_shell does not have the user parameter that asyncio has

Open
#618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Cython
Stars
11.9k
Forks
616
PR merge metrics
No merged PRs in 30d

Description

  • uvloop version: 0.20.0
  • Python version: 3.12.3
  • Platform: Ubuntu 24
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: yes

Below is a slightly modified minimal example from the stdlib, with the addition of the user parameter.
https://docs.python.org/3/library/asyncio-subprocess.html

It will work with asyncio, but the parameter is missing for uvloop in the corresponding method:
TypeError: __subprocess_run() got an unexpected keyword argument 'user'

import asyncio
import getpass

import uvloop


async def run(cmd, user: None | int | str = getpass.getuser()):
    proc = await asyncio.create_subprocess_shell(
        cmd,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
        user=user,
    )

    stdout, stderr = await proc.communicate()

    print(f"[{cmd!r} exited with {proc.returncode}]")
    if stdout:
        print(f"[stdout]\n{stdout.decode()}")
    if stderr:
        print(f"[stderr]\n{stderr.decode()}")


asyncio.run(run("ls /tmp"))  # this works


uvloop.install()
asyncio.run(run("ls /tmp"))  # this errors

Could this be fixed/enhanced? This is very useful for scenarios where both changing the user and environment variables are required, since doing "su" to another user does not transfer the environment variables, and it then needs to be handled in a rather tedious way.

Thank you!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with uvloop's create_subprocess_shell implementation and compare its accepted arguments with the Python asyncio subprocess documentation. Reproduce the provided example on uvloop and confirm that the user parameter is accepted and behaves consistently with asyncio without raising the unexpected-keyword TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.