Summary
A tempfile.TemporaryDirectory created while restoring a bookmarked file input is cleaned up only via session.on_ended(). If the session never ends, the directory survives until the object is garbage collected, at which point tempfile emits a ResourceWarning: Implicitly cleaning up <TemporaryDirectory ...>.
https://github.com/posit-dev/py-shiny/blob/main/shiny/input_handler.py#L252-L254
if len(value_list) > 0:
tempdir_root = tempfile.TemporaryDirectory()
session.on_ended(lambda: tempdir_root.cleanup())
Impact
Low. In a running app the session ends and the callback fires, so this is mostly a test-environment artifact — a unit test that builds a session and never closes it leaves the directory to the collector.
It became visible when the unit suite adopted filterwarnings = error in #2480: the ResourceWarning is raised inside a finalizer, becomes an unraisable exception, and pytest reports it as a PytestUnraisableExceptionWarning against whichever test happened to be running when the collector fired (test_theme_css_compiles_and_is_cached on the oldest-deps job). Because the attribution is random, ResourceWarning is now ignored in pytest.ini; that ignore hides this leak rather than fixing it.
Note that shiny/ui/_theme.py deliberately relies on GC-time cleanup for its own temp directories (see theme_temporary_directories), so it is a second, intentional source of the same warning class.
Possible resolutions
- Leave as-is and close — the on-ended cleanup is correct for real sessions, and the warning only appears in tests.
- Make the test harness close its sessions, so the callback runs and the ignore in
pytest.ini can be narrowed or dropped.
- Suppress the warning at the source by cleaning up deterministically where the lifetime is known.
Filing this so the decision is recorded rather than lost behind the pytest.ini ignore.
Summary
A
tempfile.TemporaryDirectorycreated while restoring a bookmarked file input is cleaned up only viasession.on_ended(). If the session never ends, the directory survives until the object is garbage collected, at which pointtempfileemits aResourceWarning: Implicitly cleaning up <TemporaryDirectory ...>.https://github.com/posit-dev/py-shiny/blob/main/shiny/input_handler.py#L252-L254
Impact
Low. In a running app the session ends and the callback fires, so this is mostly a test-environment artifact — a unit test that builds a session and never closes it leaves the directory to the collector.
It became visible when the unit suite adopted
filterwarnings = errorin #2480: theResourceWarningis raised inside a finalizer, becomes an unraisable exception, and pytest reports it as aPytestUnraisableExceptionWarningagainst whichever test happened to be running when the collector fired (test_theme_css_compiles_and_is_cachedon the oldest-deps job). Because the attribution is random,ResourceWarningis now ignored inpytest.ini; that ignore hides this leak rather than fixing it.Note that
shiny/ui/_theme.pydeliberately relies on GC-time cleanup for its own temp directories (seetheme_temporary_directories), so it is a second, intentional source of the same warning class.Possible resolutions
pytest.inican be narrowed or dropped.Filing this so the decision is recorded rather than lost behind the
pytest.iniignore.