fix: suppress unawaited Future warning in _schedule_run_in_terminal#22851
Closed
danbedford wants to merge 1 commit into
Closed
fix: suppress unawaited Future warning in _schedule_run_in_terminal#22851danbedford wants to merge 1 commit into
danbedford wants to merge 1 commit into
Conversation
In prompt_toolkit 3.0.52, run_in_terminal() is a regular function that returns an asyncio.Future (via ensure_future). Discarding the return value lets Python GC it without calling result(), which in Python 3.12+ fires 'coroutine was never awaited' warnings that bubble into process_loop's exception handler. Fix: capture the return value and attach a no-op done_callback so the Future is properly collected. The callback itself still executes normally (the Future was already scheduled on the event loop via ensure_future).
This was referenced May 10, 2026
Closed
Contributor
|
Closing as already fixed on Triage notes (medium confidence): If you still see this on the latest version, please reopen with reproduction steps. (Bulk-closed during a CLI triage sweep.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In prompt_toolkit 3.0.52, run_in_terminal() is a regular function that returns an asyncio.Future (via ensure_future). Discarding the return value lets Python GC it without ever calling result(), which in Python 3.12+ fires "coroutine was never awaited" RuntimeWarnings that bubble into process_loop exception handler and get logged as process_loop unhandled error.
Root Cause
_schedule_run_in_terminal() checked asyncio.iscoroutinefunction(run_in_terminal) — which is False for pt 3.0.52 (it is a sync function that internally wraps a coroutine). So the else branch called run_in_terminal(callback) and discarded the returned Future.
The callback did execute (it was already scheduled via ensure_future), but the discarded Future triggered the GC warning.
Fix
Capture the return value from run_in_terminal(callback) and, if it is an asyncio.Future, attach a no-op done_callback so the Future is properly collected without warnings.
Impact