Skip to content

Unclosed client session error printed after exiting Textual app #49

@tconbeer

Description

@tconbeer

On Textual 6.4 and textual-dev==1.8.0, running Harlequin with:

uv run textual run --dev -c harlequin

Upon exit, this error is printed:

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7efee5140cd0>

Adding the following code before starting the Textual app lets us see the source of the unclosed session:

    import asyncio
    import warnings
    import tracemalloc
    tracemalloc.start()

    asyncio.get_event_loop().set_debug(True)
    warnings.simplefilter("always", ResourceWarning)

That points to the client module in this package:

/home/tco/open/harlequin/.venv/lib/python3.10/site-packages/aiohttp/client.py:453: ResourceWarning: Unclosed client session <aiohttp.client.ClientSession object at 0x7fbe51bbc2b0>
  _warnings.warn(
Object allocated at (most recent call last):
  File "/home/tco/open/harlequin/.venv/lib/python3.10/site-packages/textual_dev/client.py", lineno 114
    self.session = aiohttp.ClientSession()
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fbe51bbc2b0>

self.session = aiohttp.ClientSession()

changing that assignment to a context manager should do the trick. PR incoming.

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