Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create_subprocess_shell does not have the user parameter that asyncio has #618

Open
PokkaKiyo opened this issue Aug 16, 2024 · 0 comments
Open

Comments

@PokkaKiyo
Copy link

  • 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant