python / python/cpython

asyncio subprocess spawn does not record the awaiting task

Abierto
#157,259 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib topic-asyncio type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en Lib/asyncio/base_subprocess.py, en BaseSubprocessTransport.init, e inspecciona la ruta de conexión de la pipe del subproceso que se muestra en el traceback. Ejecuta la reproducción de asyncio proporcionada y confirma que la tarea interna de conexión de la pipe informa de una arista “Awaited by” para la tarea de spawn; después, verifica que la arista se descarta mediante el callback de finalización.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend, operating-systems
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Activo
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.