Calling an async command from an active event loop raises RuntimeError and leaves an unawaited coroutine
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 78/100
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
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de google/python-fire
-
Async functools.partial calls return an unawaited coroutineTalvez já em andamento @rioyu123 assumiu há 10 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
google/python-fire#711 ·
-
WrappedJoin adds an empty line before an oversized first itemTalvez já em andamento @GreedyC assumiu há 18 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
google/python-fire#705 ·
-
Brace-based template arguments crash literal parsing with TypeErrorTalvez já em andamento @codewithfourtix assumiu há 18 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
google/python-fire#703 ·
-
Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFireTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
google/python-fire#693 ·
-
Mio ❤️Aberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 1/100
google/python-fire#709 · 2 comentários ·
Todas as issues de google/python-fire
Issues semelhantes
-
idxmax/idxmin raise ValueError when a single partition is all-NATalvez já em andamento @Jason10191019999 assumiu hoje. Abertaneeds triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 3 dias
-
Old versions of datamodelsAbertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
-
[BUG]: Windows GUI package of v1.17.0-rc3 has no GTK DLLsTalvez já em andamento @andrut-ds assumiu hoje. Abertabug CI/CD Pactus-GUI Windows
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
pactus-project/pactus#2428 ·
Mantenedores costumam responder em até 1 dia
-
DiskDataset.reshard() can hang with a zero or negative shard sizeTalvez já em andamento @Programmer-Develops assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 19 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
GNS3/gns3-server#3017 · 1 comentário ·
Mantenedores costumam responder em até 1 dia