Command palette waits for a 0.1 s timeout after the last provider finishes before showing results
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
Start with CommandPalette._search_for, especially its wait on commands.get() and how provider tasks finish; the issue includes a reproduction script using InstantProvider and TimedPalette. Verify that the list refreshes promptly after the final provider finishes, without the roughly 0.1-second delay.
Written by the indexing model from the issue text.
Description
Hi! I hit this while writing generated tests against Textual's widgets.
CommandPalette._search_for loops while any provider's task is running, waiting on wait_for(commands.get(), 0.1). When a provider finishes, it puts nothing on the queue, so if the loop is already waiting it sleeps until the timeout before it notices. The list is filled at the end of the search, so with a provider that does any async work after its last hit, the results appear about 0.1 s late on every keystroke.
import asyncio
from time import perf_counter
import textual
from textual.app import App
from textual.command import CommandPalette, Hit, Hits, Provider
provider_done: list[float] = []
list_filled: list[float] = []
class InstantProvider(Provider):
async def search(self, query: str) -> Hits:
yield Hit(1.0, f"Result for {query!r}", lambda: None)
await asyncio.sleep(0.01) # e.g. checking a source for more results
provider_done.append(perf_counter())
class TimedPalette(CommandPalette):
def _refresh_command_list(self, command_list, commands, clear_current) -> None:
super()._refresh_command_list(command_list, commands, clear_current)
list_filled.append(perf_counter())
class PaletteApp(App):
COMMANDS = {InstantProvider}
async def main() -> None:
app = PaletteApp()
async with app.run_test() as pilot:
app.push_screen(TimedPalette())
await pilot.pause()
for key in "abcde":
provider_done.clear()
list_filled.clear()
await pilot.press(key)
await pilot.pause(0.3)
delay = list_filled[-1] - provider_done[-1]
print(f"query {key!r}: list filled {delay * 1000:.0f} ms after the provider finished")
await pilot.press("backspace")
await pilot.pause(0.3)
print("Textual", textual.__version__)
asyncio.run(main())
Output on Textual 8.2.7:
query 'a': list filled 92 ms after the provider finished
query 'b': list filled 93 ms after the provider finished
query 'c': list filled 92 ms after the provider finished
query 'd': list filled 91 ms after the provider finished
query 'e': list filled 92 ms after the provider finished
Main at 5e5b7ef gives 91 to 92 ms. (TimedPalette only records when the list is refreshed.)
A provider that finishes in the same step as its last put doesn't see the delay, which is probably why it isn't obvious with the built-in providers. I expected the list to fill as soon as the last provider is done. A small fix is to wake the loop when a provider's task finishes, using a done callback that puts a None marker on the queue. With that, the same script gives 2 to 3 ms. I have a PR with a test ready.
- Dominant language
- Python
- Stars
- 37.7k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Textualize/textual
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6790 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Textualize/textual#6789 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6787 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Textualize/textual#6782 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Textualize/textual#6778 · 1 comment ·
All issues in Textualize/textual
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day