MagicStack / MagicStack/uvloop
uvloop runs at_fork hook when running subprocess
未關閉
還沒有人認領這個 Issue。
- 主要語言
- Cython
- 星號
- 11.9k
- 分支
- 616
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Speaking about os.register_at_fork python docs explicitly state:
These calls are only made if control is expected to return to the Python interpreter. A typical subprocess launch will not trigger them as the child is not going to re-enter the interpreter.
The standard asyncio loop behaves this way. But uvloop doesn't. Repro:
import asyncio
import os
import uvloop
def hook():
os.write(2, b"TRIGGERED\n")
async def run():
process = await asyncio.create_subprocess_exec(
"uptime",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
start_new_session=True
)
stdout, stderr = await process.communicate()
print(f"STDOUT: {stdout.decode('utf-8').strip()}")
if __name__ == "__main__":
os.register_at_fork(after_in_child=hook)
print("asyncio")
asyncio.run(run())
print("uvloop")
uvloop.install()
asyncio.run(run())
Output:
asyncio
STDOUT: 16:56:42 up 35 days, 6:20, 1 user, load average: 5.21, 4.34, 4.27
uvloop
TRIGGERED
STDOUT: 16:56:42 up 35 days, 6:20, 1 user, load average: 5.21, 4.34, 4.27
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先追蹤 uvloop 對 asyncio.create_subprocess_exec 的處理,以及在 uvloop.install() 之後使用的 fork 路徑,並將其與標準 asyncio 迴圈和 os.register_at_fork 的行為進行比較。使用 uptime 子程序重新執行提供的重現;當此次子程序啟動未觸發 after_in_child hook 時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 58/100