asyncio subprocess spawn does not record the awaiting task
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
The internal subprocess pipe-connect task registers no awaited_by edge
Repro:
import asyncio, sys
async def main():
spawn = asyncio.create_task(
asyncio.create_subprocess_exec(sys.executable, '-c', 'pass',
stdin=asyncio.subprocess.PIPE),
name='spawn')
await asyncio.sleep(0)
await asyncio.sleep(0)
for t in asyncio.all_tasks() - {asyncio.current_task()}:
asyncio.print_call_graph(t)
proc = await spawn
await proc.wait()
asyncio.run(main())
Actual:
* Task(name='spawn', id=0x103e00b90)
+ Call stack:
| File '/Users/timofeiivankov/cpython/Lib/asyncio/unix_events.py', line 211, in async _UnixSelectorEventLoop._make_subprocess_transport()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1839, in async BaseEventLoop.subprocess_exec()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/subprocess.py', line 249, in async create_subprocess_exec()
* Task(name='Task-2', id=0x103b7d0a0)
+ Call stack:
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1753, in async BaseEventLoop.connect_write_pipe()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_subprocess.py', line 188, in async BaseSubprocessTransport._connect_pipes()
Expected:
* Task(name='spawn', id=0x105620b90)
+ Call stack:
| File '/Users/timofeiivankov/cpython/Lib/asyncio/unix_events.py', line 211, in async _UnixSelectorEventLoop._make_subprocess_transport()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1839, in async BaseEventLoop.subprocess_exec()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/subprocess.py', line 249, in async create_subprocess_exec()
* Task(name='Task-2', id=0x10539d0a0)
+ Call stack:
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1753, in async BaseEventLoop.connect_write_pipe()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_subprocess.py', line 194, in async BaseSubprocessTransport._connect_pipes()
+ Awaited by:
* Task(name='spawn', id=0x105620b90)
+ Call stack:
| File '/Users/timofeiivankov/cpython/Lib/asyncio/unix_events.py', line 211, in async _UnixSelectorEventLoop._make_subprocess_transport()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 1839, in async BaseEventLoop.subprocess_exec()
| File '/Users/timofeiivankov/cpython/Lib/asyncio/subprocess.py', line 249, in async create_subprocess_exec()
Proposed fix: register the edge in BaseSubprocessTransport.__init__ and discard it in doe callback
I have a fix ready for that
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Guia de contribuição
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 em Lib/asyncio/base_subprocess.py, em BaseSubprocessTransport.init, e inspecione o caminho de conexão do pipe do subprocesso mostrado no traceback. Execute a reprodução fornecida de asyncio e confirme que a tarefa interna de conexão do pipe relata uma aresta “Awaited by” para a tarefa de spawn; em seguida, verifique que a aresta é descartada pelo callback de conclusão.
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
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Ativa
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 45/100