MagicStack / MagicStack/uvloop

create_subprocess_shell does not have the user parameter that asyncio has

未关闭
#618 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Cython
星标
11.9k
派生
616
PR 合并指标
30 天内没有已合并 PR

描述

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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 uvloop 的 create_subprocess_shell 实现入手,将其接受的参数与 Python asyncio subprocess 文档进行比较。在 uvloop 上复现所提供的示例,并确认 user 参数能够被接受,且其行为与 asyncio 一致,不会引发 unexpected-keyword TypeError。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。