Writing to a `Log` before it's mounted crashes the app (`WorkerFailed: NoActiveAppError`)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Start by tracing Log.write_line/write_lines into _log.py's _update_size worker and compare how RichLog.write handles writes before mounting. Reproduce with the supplied App.run(headless=True) example; run_test() may not reliably expose the race. Done means pre-mount writes no longer crash and a regression test covers the App.run() behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Textual's widgets.
Writing to a Log in compose(), before yielding it, crashes the app when it's run with App.run():
from textual.app import App, ComposeResult
from textual.widgets import Log
class LogApp(App):
def compose(self) -> ComposeResult:
log = Log()
log.write_line("hello") # written before the Log is yielded
yield log
def on_mount(self) -> None:
self.set_timer(0.05, self.exit)
if __name__ == "__main__":
app = LogApp()
app.run(headless=True)
print("return code:", app.return_code)
Output (the same on 8.2.7 and on main at 5e5b7ef; traceback trimmed to the frames that matter):
LookupError: <ContextVar name='active_app' at 0x...>
During handling of the above exception, another exception occurred:
worker.py:370 in _run self._result = await self.run()
worker.py:326 in _run_threaded return await loop.run_in_executor(None, runner, self._work)
_log.py:141 in _update_size self.app.call_from_thread(self._update_maximum_width, ...)
message_pump.py:264 in app raise NoActiveAppError()
NoActiveAppError
return code: 1
Running that app 500 times in a loop with app.run(headless=True) failed 500 of 500 times, on 8.2.7 and on main. Under run_test() the same app passed 300 of 300 runs, so tests written with the pilot mostly don't show it. With the eager task factory set on the loop (as run() / run_async() do), run_test() failed 1 run in 50, so it's a race, and under run() the thread wins it every time here.
write_lines() starts the _update_size thread worker, which calls self.app from the thread. active_app isn't set in the executor thread, so app falls back to walking _parent, and fails if the Log hasn't been attached yet.
I'd expect a Log to accept writes before it's mounted. RichLog does (50 of 50 runs of the same app with RichLog.write exit cleanly).
Textual 8.2.7 and main (5e5b7ef), Python 3.13, macOS.
- 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
-
author-page correction move-papers
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
acl-org/acl-anthology#10978 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
PostgreSQL results table stores labels with single quotes, and a double quote in a label fails the writeForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
HKUDS/CLI-Anything#652 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Dao-AILab/flash-attention#3191 ·
I maintainer di solito rispondono entro 4 giorni