Skip to content

Bug: Engine.__init__ creates a separate tokio runtime, conflicting with async environments #92

@zTgx

Description

@zTgx

Description

PyEngine::new() in python/src/engine.rs:116 creates its own Runtime::new() and calls rt.block_on() to build the engine. This creates a separate tokio runtime from the one used by pyo3_async_runtimes for async method calls.

This can cause issues when:

  1. The user is already running an async event loop (e.g. Jupyter, FastAPI)
  2. Multiple Engine instances are created — each spawns its own runtime
  3. The background graph rebuild task runs on a different runtime than the engine's async methods

Relevant Code

  • python/src/engine.rs:116-143PyEngine::new() with Runtime::new().block_on()

Suggested Fix

Use pyo3_async_runtimes::tokio::get_runtime() to share a single tokio runtime, or lazily initialize the engine on first async method call instead of in __init__.

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