Skip to content

RuntimeWarning: coroutine 'process_before_invoke_callbacks' was never awaited #96

Description

@acere

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions