Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Inizia in fire/core.py, in _CallAndUpdateTrace, dove, secondo l’issue, la coroutine viene passata a loop.run_until_complete; confronta questo percorso con il test esistente testFireAsyncio in fire/fire_test.py. Aggiungi un test di regressione per chiamare fire.Fire all’interno di un event loop attivo e verifica che produca il comportamento documentato senza generare un avviso per una coroutine non attesa. L’issue suggerisce di documentare il comportamento supportato in docs/guide.md.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 28.2k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/python-fire
-
Setup docs still say `python setup.py install`, but `setup.py` was removedForse già presa @GreedyC l’ha presa 1 giorno fa. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 93/100
google/python-fire#718 · 1 commento ·
-
Async functools.partial calls return an unawaited coroutineForse già presa @rioyu123 l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google/python-fire#711 ·
-
WrappedJoin adds an empty line before an oversized first itemForse già presa @GreedyC l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google/python-fire#705 ·
-
Brace-based template arguments crash literal parsing with TypeErrorForse già presa @codewithfourtix l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google/python-fire#703 ·
-
Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFireForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
google/python-fire#693 ·
Tutte le issue di google/python-fire
Issue simili
-
[Resource]: LoreApertaresource-submission validation-passed
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
hesreallyhim/awesome-claude-code#3234 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openminion/openminion#376 ·
I maintainer di solito rispondono entro 1 giorno
-
Type: ☹︎ Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
posit-dev/great-tables#1028 ·
I maintainer di solito rispondono entro 1 giorno
-
integration: apple_tv
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
home-assistant/core#188282 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
A "since" range is worded as a career: "the past two seasons" says "regular season career (2025 on)"ApertaP4: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
jeffknupp/association#538 ·