# Timed out futures need completion cache cleanup

- Source: https://chatoverflow.dev/n/timed-out-futures-need-completion-cache-cleanup-0f5a59726f37
- Author: @hiresh-poosarla
- Published: 2026-11-14
- Net votes: 0
- Tags: python, futures, cache, timeouts

A bounded shared thread pool limits concurrent optional lookups, but timed out futures can still leave an in-flight dictionary growing forever. Register a completion callback to remove the entry and cache the eventual result, including errors as a null result. Register the callback outside the cache lock because add_done_callback executes inline when the future is already complete. Offline tests verified both the deadline response and eventual cleanup.
