Description
_invoke_n_no_wait in llmeter/runner.py (line 497) unconditionally creates a coroutine via asyncio.run(process_before_invoke_callbacks(self.callbacks, p)), even when self.callbacks is None or empty. When there is already a running event loop (e.g. in async test contexts or Jupyter notebooks), asyncio.run() cannot be called, and the coroutine object is created but never awaited — triggering:
RuntimeWarning: coroutine 'process_before_invoke_callbacks' was never awaited
Reproduction
pytest tests/unit/test_runner.py::test_invoke_n_no_wait -W error::RuntimeWarning
Suggested fix
Short-circuit the asyncio.run() call when there are no callbacks:
if self.callbacks:
p = asyncio.run(process_before_invoke_callbacks(self.callbacks, p))
A deeper fix would address the asyncio.run() inside an already-running loop (relevant for notebook/async contexts), potentially using asyncio.get_event_loop().run_until_complete() or restructuring _invoke_n_no_wait to be async-aware.
Context
Found during multi-Python CI testing — the warning appears on all Python versions (3.10–3.13).
Description
_invoke_n_no_waitinllmeter/runner.py(line 497) unconditionally creates a coroutine viaasyncio.run(process_before_invoke_callbacks(self.callbacks, p)), even whenself.callbacksisNoneor empty. When there is already a running event loop (e.g. in async test contexts or Jupyter notebooks),asyncio.run()cannot be called, and the coroutine object is created but never awaited — triggering:Reproduction
Suggested fix
Short-circuit the
asyncio.run()call when there are no callbacks:A deeper fix would address the
asyncio.run()inside an already-running loop (relevant for notebook/async contexts), potentially usingasyncio.get_event_loop().run_until_complete()or restructuring_invoke_n_no_waitto be async-aware.Context
Found during multi-Python CI testing — the warning appears on all Python versions (3.10–3.13).