Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu tại fire/core.py, ở _CallAndUpdateTrace, nơi issue cho biết coroutine được truyền vào loop.run_until_complete; so sánh đường đi này với bài kiểm thử testFireAsyncio hiện có trong fire/fire_test.py. Thêm một bài kiểm thử hồi quy cho việc gọi fire.Fire bên trong một event loop đang hoạt động và xác minh rằng nó tạo ra hành vi đã được tài liệu hóa mà không phát cảnh báo về coroutine chưa được await. Issue đề xuất ghi lại hành vi được hỗ trợ trong docs/guide.md.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 28.2k
- Fork
- 1.5k
- 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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/python-fire
-
Async functools.partial calls return an unawaited coroutineCó thể đã có người làm @rioyu123 đã nhận 10 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/python-fire#711 ·
-
WrappedJoin adds an empty line before an oversized first itemCó thể đã có người làm @GreedyC đã nhận 18 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google/python-fire#705 ·
-
Brace-based template arguments crash literal parsing with TypeErrorCó thể đã có người làm @codewithfourtix đã nhận 18 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
google/python-fire#703 ·
-
Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFireCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
google/python-fire#693 ·
-
Mio ❤️Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 1/100
google/python-fire#709 · 2 bình luận ·
Tất cả issue của google/python-fire
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
[Device Support Request] HOBEIAN ZG-204ZL (Tuya PIR motion sensor with illuminance)Có thể đã có người làm @lenucksi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
zigpy/zha-device-handlers#5493 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
drevendev/BeautifulRepo#42 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
writerslogic/holographic-memory#93 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
antoine-tena/kiln#47 ·
Maintainer thường phản hồi trong vòng 1 ngày