Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Server.serve_forever() isn't cancelled when Server.close() is called

未關閉
#602 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python

研究方向

首先,將 uvloop 的伺服器行為與 Lib/asyncio/base_events.py 第 341–344 行附近連結的 CPython 實作進行比較,重點關注 Server.serve_forever() 和 Server.close()。使用提供的 SIGTERM 範例重現此問題,並確認關閉伺服器會使 serve_forever() 引發 asyncio.CancelledError,並在退出前列印「Shutting down」。

由索引模型根據 Issue 內容生成。

描述

  • uvloop version: 0.19.0
  • Python version: 3.10.12 (3.10.12-1~22.04.3)
  • Platform: Ubuntu 22.04.4
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: Yes
  • Does uvloop behave differently from vanilla asyncio? How?: Yes, described below.

With stock asyncio, after awaiting on Server.serve_forever(), calling Server.close() causes the await statement to throw CancelledError. With uvloop's implementation, the listening socket is correctly closed, however the await statement blocks indefinitely.

Example:

async def run_server():
    async with await asyncio.start_server(lambda r,w: w.close(), '127.0.0.1', 8080) as server:
        server.get_loop().add_signal_handler(15, lambda: server.close())
        try:
            await server.serve_forever()
        except asyncio.CancelledError:
            print('Shutting down')

uvloop.run(run_server())

The uvloop version closes the listening socket in response to SIGTERM, but never exits. The stock version prints Shutting down and exits.

Here's the CPython source where this is implemented:

https://github.com/python/cpython/blob/v3.8.18/Lib/asyncio/base_events.py#L341-L344

Thanks for taking a look!

主要語言
Cython
星號
11.9k
分支
615
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

MagicStack/uvloop 的其他 Issue

查看 MagicStack/uvloop 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。