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

'cannot reuse already awaited coroutine' with timed_window on Python 3.7.5

Đang mở
#284 0 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
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
stream-processing

Hướng nghiên cứu

Start with the timed_window path in streamz/core.py around line 917 and the Sink.update method around line 535. Reproduce the Python 3.7.5 example, then inspect tests/core.py for related asynchronous sink coverage. Done means a regression test demonstrates the repeated-await failure and the chosen fix preserves existing tests.

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

Mô tả

Using timed_window in Python 3.7.5 can sometimes lead to a coroutine being awaited more than once.

Here's a sample program:

async def my_sink(x):
    print(x)
    await sleep(2)
    # raise Exception("Blah!")


async def main():
    source = Stream(asynchronous=True)
    source.timed_window(interval=1).sink(my_sink)

    for x in range(100):
        await source.emit(x)
        await sleep(0.2)


if __name__ == "__main__":
    run(main(), debug=True)

I narrowed down the reason to the same coroutine being possibly returned more than once in https://github.com/python-streamz/streamz/blob/master/streamz/core.py#L917.

A way to work around this issue is to create a task that runs the coroutine. Modifying the update method of the Sink class to return a task fixes the issue. The tests in tests/core.py continue pass.

diff --git a/streamz/core.py b/streamz/core.py
index fe588ed..6916f19 100644
--- a/streamz/core.py
+++ b/streamz/core.py
@@ -535,7 +535,7 @@ class sink(Stream):
     def update(self, x, who=None):
         result = self.func(x, *self.args, **self.kwargs)
         if gen.isawaitable(result):
-            return result
+            return gen.convert_yielded(result)
         else:
             return []

I'm quite sure this can break something else. What am I missing?

Also, how can we go about writing a test case that demonstrates the issue?

Ngôn ngữ chính
Python
Star
1.3k
Fork
149
Merge trung bình
17 giờ 39 phút
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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 khác của python-streamz/streamz

Tất cả issue của python-streamz/streamz

Issue tương tự

Thêm issue về Python

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.