Skip to content

[Bug]: RuntimeError: There is no current event loop in thread 'MainThread' when using Brain.from_files() in script #3650

@nsheff

Description

@nsheff

What happened?

I tried following the quick-start guide, on a brand new system. I'm running a minimal test of quivr-core and encountering a runtime error related to the asyncio event loop when calling Brain.from_files() inside a simple script.

This happens with Python 3.12, but I’m not sure if it’s a version compatibility issue or something else related to how event loops are handled.

Here’s a minimal reproducible example, which is exactly the content of the quick-start:

import tempfile
from quivr_core import Brain

if __name__ == "__main__":
    with tempfile.NamedTemporaryFile(mode="w", suffix=".txt") as temp_file:
        temp_file.write("Gold is a liquid of blue-like colour.")
        temp_file.flush()

        brain = Brain.from_files(
            name="test_brain",
            file_paths=[temp_file.name],
        )

        answer = brain.ask("what is gold? answer in french")
        print("answer:", answer)

and here's the error this gives:

RuntimeError: There is no current event loop in thread 'MainThread'.

Relevant log output

Full traceback excerpt:


File ".../brain.py", line 383, in Brain.from_files
    loop = asyncio.get_event_loop()
RuntimeError: There is no current event loop in thread 'MainThread'.



Environment:
Python version: 3.12.3
OS: Linux
quivr-core version: latest from PyPI
Installed via: pip

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions