You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine #716
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:
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.
Activity