Coroutine getting lost after sleep
还没有人认领这个 Issue。
评估
调研方向
从最小复现示例的 GeneratorQueryHandler.items 方法开始,在快速输入 "chunktest asdf" 时观察其行为。比较 yield 后 sleep 与 yield 前 sleep 的情况,并跟踪 coroutine 取消和 ctx.isValid 的处理方式。完成的标准是:post-yield sleep 后,五个 item chunk 仍会继续填充,且不会丢失 coroutine。
由索引模型根据 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:
- "Web search"
- 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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
-
[BUG] Clipboard History: Buffer over-read in WideCharToMultiByte on double-click paste可能已有人在做 @softmgr 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
notepad-plus-plus/notepad-plus-plus#18519 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
justcallmekoko/ESP32Marauder#1635 ·
维护者通常 1 天内回复
-
3.7.6-dev commit 80481ea - files not centered when resolution differs and zoom = "pixel-to-pixel"未关闭
难度 2/5 1-3 小时 新手友好度 78/100
grizzlypeak3d/DJV#931 ·