Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

'cannot reuse already awaited coroutine' with timed_window on Python 3.7.5

Abierto
#284 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start with the timed_window path in streamz/core.py around line 917 and the Sink.update method around line 535. Reproduce the Python 3.7.5 example, then inspect tests/core.py for related asynchronous sink coverage. Done means a regression test demonstrates the repeated-await failure and the chosen fix preserves existing tests.

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

Descripción

Using timed_window in Python 3.7.5 can sometimes lead to a coroutine being awaited more than once.

Here's a sample program:

async def my_sink(x):
    print(x)
    await sleep(2)
    # raise Exception("Blah!")


async def main():
    source = Stream(asynchronous=True)
    source.timed_window(interval=1).sink(my_sink)

    for x in range(100):
        await source.emit(x)
        await sleep(0.2)


if __name__ == "__main__":
    run(main(), debug=True)

I narrowed down the reason to the same coroutine being possibly returned more than once in https://github.com/python-streamz/streamz/blob/master/streamz/core.py#L917.

A way to work around this issue is to create a task that runs the coroutine. Modifying the update method of the Sink class to return a task fixes the issue. The tests in tests/core.py continue pass.

diff --git a/streamz/core.py b/streamz/core.py
index fe588ed..6916f19 100644
--- a/streamz/core.py
+++ b/streamz/core.py
@@ -535,7 +535,7 @@ class sink(Stream):
     def update(self, x, who=None):
         result = self.func(x, *self.args, **self.kwargs)
         if gen.isawaitable(result):
-            return result
+            return gen.convert_yielded(result)
         else:
             return []

I'm quite sure this can break something else. What am I missing?

Also, how can we go about writing a test case that demonstrates the issue?

Lenguaje dominante
Python
Estrellas
1.3k
Forks
149
Merge medio
17 h 39 min
PR fusionados (30 d)
1

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.

Más de python-streamz/streamz

Todos los issues de python-streamz/streamz

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.