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

Coroutine getting lost after sleep

Abierto
#12 1 comentario 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
50/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
desktop

Línea de trabajo

Comienza con el método items de GeneratorQueryHandler del reproductor mínimo y observa su comportamiento mientras escribes "chunktest asdf" rápidamente. Compara dormir después del yield con dormir antes de él, y sigue cómo se gestionan la cancelación de la coroutine y ctx.isValid. Se considera terminado cuando los cinco chunks de elementos siguen rellenándose después de un sleep posterior al yield sin perder la coroutine.

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

Descripción

I'm working on a plugin with a GeneratorQueryHandler which yields one item as a result, and then sleeps for a bit, and then fetches a result from an API and yields those items as well. So basically, it yields two chunks:

  1. "Web search"
  2. First 5 results of the suggestions

But I've noticed that the coroutine seems to just stop getting called sometimes. I was able to boil it down to a minimal reproducer:

import time

from albert import *

md_iid = "5.0"
md_name = "chunktest"
md_description = "testing multiple chunks of items"
md_authors = ["@brenns10"]


class Plugin(PluginInstance, GeneratorQueryHandler):

    def __init__(self):
        PluginInstance.__init__(self)
        GeneratorQueryHandler.__init__(self)

    def defaultTrigger(self):
        return "chunktest "

    def items(self, ctx):
        for i in range(5):
            if not ctx.isValid:
                info("exiting early")
                return
            info(f"yielding item {i}")
            yield [
                StandardItem(
                    id=f"item{i}",
                    text=f"Item {i}",
                    subtext="details",
                    actions=[
                        Action(
                            id="act",
                            text="Open Google",
                            callable=lambda: runTerminal("echo hi"),
                        )
                    ],
                )
            ]
            time.sleep(0.1)
            info("finished sleeping")
        info("done")

When I load this plugin, and then type "chunktest asdf" (type really fast), I only get "Item 0", and the logs look like this:

17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [warn:albert.wbm] Item retured null icon: python.chunktest.item0
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [info:albert.python.chunktest] finished sleeping
17:25:52 [info:albert.python.chunktest] yielding item 1
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:52 [info:albert.python.chunktest] yielding item 0
17:25:53 [info:albert.python.chunktest] yielding item 0
17:25:53 [info:albert.python.chunktest] yielding item 0

The remaining 4 items never get populated. Here is a video that shows what I mean.

However, if you go ahead and move the time.sleep() call just before the yield statement, rather than after it, you'll get the behavior I expect. That is, the results keep getting replaced each time I type a new keystroke, and they slowly populate whenever I pause. Here's the video of this behavior.

It seems to me like there's something going on with this time.sleep() call directly after the yield. I notice I never see the "exiting early" message logged, which may or may not be related.

Lenguaje dominante
C++
Estrellas
3
Forks
4
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

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.

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.