Skip to content

Live class eagerly creates an asyncio event loop at class-definition time, causing ResourceWarning: unclosed event loop merely from importing databento #136

Description

@docxology

databento/live/client.py defines Live._loop = asyncio.new_event_loop()
as a class-body attribute (line 78 in v0.78.0), executed at class-definition
time — i.e. at import time of databento.live.client, not when Live is
instantiated. The backing thread is only started lazily in __init__
(Live._thread.start(), gated by is_alive()), so the loop created at
import time is never run and never explicitly closed if Live is never
instantiated.

At interpreter shutdown, Python's GC finalizes the unused loop and emits:

ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>

Repro — this warning fires from only importing the package, no Live
usage at all:

$ python3 -W always -c "import databento"
... (warning appears at process exit)

This is distinct from #99 (which asked about injecting an existing loop
for async integration) — here the problem is that merely importing
databento allocates OS-level resources (an event loop) that are never
used or released if the caller's code path never touches Live at all
(e.g. only uses the historical/batch APIs or enum/schema constants).

Suggested fix: defer loop creation to Live.__init__ (or a lazy
classmethod/property) instead of the class body, so importing the module
has no side effects.

Environment: databento-python 0.78.0, Python 3.14.4, macOS arm64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions