Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte Adaptée aux débutants
#716 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
cli, testing

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

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de google/python-fire

Toutes les issues de google/python-fire

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.