Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Coroutine getting lost after sleep

オープン
#12 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
desktop

調査の方向性

最小再現例の GeneratorQueryHandler.items メソッドから始めて、「chunktest asdf」と素早く入力したときの動作を確認します。yield の後に sleep する場合と、その前に sleep する場合を比較し、coroutine のキャンセルと ctx.isValid がどのように処理されるかを追跡します。post-yield sleep の後も、coroutine を失うことなく 5 つすべての item chunk の生成が継続すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
3
フォーク
4
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。