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

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

Đang mở Phù hợp với người mới
#716 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@aashish254 đang làm issue này rồi.

Từ ngày 20/10/2026.

  • #717 của @aashish254 — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
cli, testing

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

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 google/python-fire

Tất cả issue của google/python-fire

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.