Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`asyncio.create_subprocess_exec`: cannot read `/dev/stdin`

Đang mở
#532 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend, operating-systems

Hướng nghiên cứu

Bắt đầu với reproducer trong test.py và so sánh hành vi của nó với vanilla asyncio trên Linux trong Docker. Truy vết việc xử lý stdin của subprocess qua uvloop/loop.pyx, uvloop/handles/stream.pyx và uvloop/handles/handle.pyx. Công việc được xem là hoàn tất khi subprocess /dev/stdin in ra b'test' dưới uvloop mà không có closed-transport error.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

  • uvloop version: uvloop==0.17.0
  • Python version: Python 3.10.10
  • Platform: Linux 0af9a1603f81 5.10.76-linuxkit #1 SMP Mon Nov 8 10:21:19 UTC 2021 x86_64 GNU/Linux (in a Docker container)
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: yes. Vanilla asyncio had a similar issue patched: https://github.com/python/cpython/issues/90522

Processes run with asyncio.create_subprocess_exec fail to read from /dev/stdin with uvloop but not with asyncio

asyncio had a similar issue fixed recently (in January 2022): https://github.com/python/cpython/issues/90522
This was backported to 3.10 and 3.11

I can reproduce this on Linux in a Docker container, with either Mac OS or Linux as hosts
I cannot reproduce this on Mac OS (seems to work fine)

Logs:

# PYTHONASYNCIODEBUG=1 python test.py
cat: /dev/stdin: No such device or address
Traceback (most recent call last):
  File "//test.py", line 16, in <module>
    asyncio.run(f())
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "//test.py", line 13, in f
    stdout, _ = await proc.communicate("test".encode("utf-8"))
  File "/usr/local/lib/python3.10/asyncio/subprocess.py", line 195, in communicate
    stdin, stdout, stderr = await tasks.gather(stdin, stdout, stderr)
  File "/usr/local/lib/python3.10/asyncio/subprocess.py", line 147, in _feed_stdin
    self.stdin.write(input)
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 325, in write
    self._transport.write(data)
  File "uvloop/handles/stream.pyx", line 674, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <WriteUnixTransport closed=True reading=False 0x7f64e3186dc0>; the handler is closed

Expected (using asyncio):

# PYTHONASYNCIODEBUG=1 python test.py
b'test'

Code to reproduce:

import asyncio

# Commenting out `uvloop` below fixes the issue
import uvloop
uvloop.install()

async def f():
    proc = await asyncio.create_subprocess_exec(
        "cat",
        "/dev/stdin",
        stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE,
    )
    stdout, _ = await proc.communicate("test".encode("utf-8"))
    print(stdout)

asyncio.run(f())
Ngôn ngữ chính
Cython
Star
11.9k
Fork
615
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MagicStack/uvloop

Tất cả issue của MagicStack/uvloop

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.