Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Coroutine getting lost after sleep

Aperta
#12 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
desktop

Direzione di ricerca

Inizia con il metodo items di GeneratorQueryHandler del riproduttore minimo e osservane il comportamento mentre digiti rapidamente "chunktest asdf". Confronta l'attesa dopo il yield con l'attesa prima di esso e traccia come vengono gestiti l'annullamento della coroutine e ctx.isValid. Il lavoro è completato quando tutti e cinque i chunk di elementi continuano a popolarsi dopo un sleep post-yield senza perdere la coroutine.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
3
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.