Command palette waits for a 0.1 s timeout after the last provider finishes before showing results
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 37.7k
- Fork
- 1.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Textualize/textual
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6790 · 2 commenti ·
-
Markdown table of contents: the node added for a skipped heading level shows the wrong numeralAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Textualize/textual#6789 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6787 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Textualize/textual#6782 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Textualize/textual#6778 · 1 commento ·
Tutte le issue di Textualize/textual
Issue simili
-
Internal ErrorApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
frappe/frappe_docker#2071 ·
I maintainer di solito rispondono entro 1 giorno
-
bug python
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
traceloop/openllmetry#4717 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Apertacomp/desktop P2 type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#157702 ·
I maintainer di solito rispondono entro 1 giorno
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenForse già presa @BahaaMattar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
I maintainer di solito rispondono entro 1 giorno