MagicStack / MagicStack/uvloop
`asyncio.create_subprocess_exec`: cannot read `/dev/stdin`
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Cython
- Estrelas
- 11.9k
- Forks
- 616
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
* **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
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 ; the handler is closed
```
Expected (using `asyncio`):
```
# PYTHONASYNCIODEBUG=1 python test.py
b'test'
```
Code to reproduce:
```py
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())
```
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo reproducer em test.py e compare o comportamento dele com o vanilla asyncio no Linux dentro do Docker. Rastreie o tratamento de stdin de subprocess por meio de uvloop/loop.pyx, uvloop/handles/stream.pyx e uvloop/handles/handle.pyx. A tarefa estará concluída quando o subprocesso `/dev/stdin` imprimir `b'test'` sob uvloop sem o closed-transport error.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend, operating-systems
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 45/100