python / python/cpython

`concurrent.futures.Executor.map` with `buffersize` should yield from buffer and raise after executor shutdown

Abierto
#146,392 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib topic-multiprocessing 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:

As pointed by @salomvary in this discussion, the behavior of concurrent.futures.Executor.map with buffersize is misleading when iterating after the executor's shutdown. There is 2 cases:

  1. Create the generator, shut down the executor, start iterating:
with ThreadPoolExecutor(1) as executor:
    iterator = executor.map(str, range(8), buffersize=2)

# start iterating after the shutdown
assert next(iterator) == "0"
assert next(iterator) == "1"
# raises StopIteration
next(iterator)

In this scenario the elements from the buffer are yielded, then the iteration is stopped.

  1. Create the generator, start the iteration, shut down the executor, continue the iteration
with ThreadPoolExecutor(1) as executor:
    iterator = executor.map(str, range(8), buffersize=2)
    # start iterating before the shutdown
    assert next(iterator) == "0"

# raises "RuntimeError: cannot schedule new futures after shutdown"
next(iterator)

In this scenario a RuntimeError is raised by the first post-shutdown next, leaving not-yet-yielded results in the buffer.


I would vote for a mix of both: yield from the buffer and then raise the exception.

(the fix would be a dozen rows)

CPython versions tested on:

3.14, 3.15

Operating systems tested on:

macOS, Linux, Windows

Linked PRs
  • gh-146395

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

Reproduce ambos escenarios de apagado del issue mediante concurrent.futures.Executor.map y su argumento buffersize. Inspecciona la ruta de iteración de Executor.map, añade después cobertura para devolver resultados almacenados en búfer antes de la excepción posterior al apagado y verifica que los ejemplos existentes se comporten como se describe.

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

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.