Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 78/100
Piste de recherche
Commencez dans fire/core.py, à _CallAndUpdateTrace, où, selon l’issue, la coroutine est passée à loop.run_until_complete ; comparez ce chemin avec le test existant testFireAsyncio dans fire/fire_test.py. Ajoutez un test de régression pour appeler fire.Fire dans une boucle d’événements active et vérifiez que le comportement documenté se produit sans avertissement concernant une coroutine non attendue. L’issue suggère de documenter le comportement pris en charge dans docs/guide.md.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 28.2k
- Forks
- 1.5k
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de google/python-fire
-
Async functools.partial calls return an unawaited coroutinePeut-être pris @rioyu123 l’a pris il y a 9 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
google/python-fire#711 ·
-
WrappedJoin adds an empty line before an oversized first itemPeut-être pris @GreedyC l’a pris il y a 17 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
google/python-fire#705 ·
-
Brace-based template arguments crash literal parsing with TypeErrorPeut-être pris @codewithfourtix l’a pris il y a 18 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
google/python-fire#703 ·
-
Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFirePeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
google/python-fire#693 ·
-
Mio ❤️Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 1/100
google/python-fire#709 · 2 commentaires ·
Toutes les issues de google/python-fire
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
mihai-vlc/sublime-jsfmt#56 ·
-
comp/cli comp/plugins P2 type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
NousResearch/hermes-agent#141917 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Go device SDK: Whisper transcriber keeps buffering and transcribing audio appended after Stop()Peut-être pris @apoorvdarshan l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
BasedHardware/omi#22770 ·
Les mainteneurs répondent en général sous 1 jour
-
bug needs-acceptance wg/router-models-inference-runtime
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
vllm-project/semantic-router#5295 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
huggingface/huggingface_hub#5210 ·
Les mainteneurs répondent en général sous 1 jour