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

Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine

未關閉 適合新手
#716 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@aashish254 已經在處理了。

開始於 2026年10月20日。

  • #717 來自 @aashish254 —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cli, testing

研究方向

從 fire/core.py 中的 _CallAndUpdateTrace 開始,issue 指出 coroutine 會在此處傳遞給 loop.run_until_complete;將這條路徑與 fire/fire_test.py 中現有的 testFireAsyncio 測試進行比較。新增一個迴歸測試,在作用中的事件迴圈內呼叫 fire.Fire,並確認它會產生文件所述的行為,且不會發出未等待 coroutine 的警告。issue 建議在 docs/guide.md 中記錄支援的行為。

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

描述

Bug

Calling an async command through fire.Fire from code that already has a running asyncio event loop raises RuntimeError: This event loop is already running and emits a warning that the command coroutine was never awaited. The same command works when called from synchronous code.

Reproduction

On master at 716bbc23d7eca949fdb682172283c8d18f742cb6, run:

import asyncio
import fire

async def target():
    return 42

async def main():
    fire.Fire(target, command=[])

asyncio.run(main())

Observed output:

RuntimeError: This event loop is already running
RuntimeWarning: coroutine 'target' was never awaited

As a control, fire.Fire(target, command=[]) from synchronous code prints and returns 42. The existing fire/fire_test.py::FireTest::testFireAsyncio test also passes; it runs outside an active event loop.

Expected behavior

Fire should either support this context or reject it with a clear, intentional error before creating an unawaited coroutine.

Likely cause and suggested fix

In fire/core.py, _CallAndUpdateTrace calls loop.run_until_complete(fn(*varargs, **kwargs)) after asyncio.get_running_loop() succeeds. A loop that is already running cannot be driven again by run_until_complete in the same thread. The smallest safe change is to detect this case before constructing the coroutine and return a clear error explaining that synchronous Fire cannot run an async command from an active loop. If support for this context is intended, an async entrypoint would need to await the command. A regression test belongs in fire/fire_test.py; docs/guide.md should state the supported behavior.

Environment: Python 3.12.10, Python Fire source version 0.7.1, Windows. Reproduced on the master revision above.

主要語言
Python
星號
28.2k
分支
1.5k
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

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

google/python-fire 的其他 Issue

查看 google/python-fire 的全部 Issue

相似的 Issue

更多 Python Issue

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

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