Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Coroutine getting lost after sleep

Đang mở
#12 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
desktop

Hướng nghiên cứu

Bắt đầu với phương thức items của GeneratorQueryHandler trong minimal reproducer và quan sát hành vi của nó khi nhập nhanh "chunktest asdf". So sánh việc sleep sau yield với việc sleep trước yield, đồng thời theo dõi cách xử lý việc hủy coroutine và ctx.isValid. Được coi là hoàn thành khi cả năm item chunk tiếp tục được điền sau một post-yield sleep mà không làm mất coroutine.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
3
Fork
4
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.