Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#716 0 comentários 0 reações 0 responsáveis Ver no GitHub

@aashish254 já está trabalhando nisso.

Desde 20/10/2026.

  • #717 de @aashish254 — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
cli, testing

Direção de pesquisa

Comece em fire/core.py, em _CallAndUpdateTrace, onde, segundo a issue, a coroutine é passada para loop.run_until_complete; compare esse caminho com o teste existente testFireAsyncio em fire/fire_test.py. Adicione um teste de regressão para chamar fire.Fire dentro de um loop de eventos ativo e verifique se ele produz o comportamento documentado sem emitir um aviso sobre uma coroutine não aguardada. A issue sugere documentar o comportamento compatível em docs/guide.md.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
28.2k
Forks
1.5k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de google/python-fire

Todas as issues de google/python-fire

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.