Repository navigation
refactor(tui): one render path for text and image plots - #328
Conversation
henryiii
left a comment
There was a problem hiding this comment.
🤖 AI text below 🤖
A cancelled render can replace a newer plot with an error. I blocked the first render of A, selected B and then A, waited for the second A to display, and released the first render with a RuntimeError. The view switched from the successful plot to the first render’s error.
_render_failed compares plot items by value, so both renders of A pass the same check. Give each newly started render a request ID, include it in RenderFailed, and check it when the UI handles the message. Keep the ID when an equal selection reuses an in-flight render. That preserves the consecutive A → A case while rejecting the stale error after A → B → A. Please add the blocked-worker sequence as a regression test.
6a8bf02 to
4ee07fe
Compare
|
🤖 AI text below 🤖 Fixed in 4ee07fe. Each started render gets a render ID, and |
4ee07fe to
f77ed07
Compare
b0b070f to
e4a4d40
Compare
Plotext and MPLPlot now subclass one frozen PlotItem dataclass. The item compares by value, so the app compares it with the last rendered item instead of a key tuple. One RequestRender message, one handler and one worker render both modes. The worker catches the errors and posts one RenderFailed message, so the item does not hold the app. Each started render gets an ID, so the report of a cancelled render is dropped, also after A -> B -> A. An equal selection keeps the ID of the running render, so its error still shows. A superseded render does not block the new one now: the data is read outside the plotext and matplotlib locks, and a progress report in a cancelled worker raises progress.CancelledError, which stops a chunked read. ViewWidget handles the entry box and the Plot button with @on. The dead dev block and the __package__ workaround in browser.py are removed. Refs #322 Assisted-by: ClaudeCode:claude-opus-5-5
e4a4d40 to
e541a6c
Compare
🤖 AI text below 🤖
Items 19, 9, part of 12, and
App._exitfrom 23 of the review issue.PlotextandMPLPlotsubclass one frozenPlotItemdataclass with the shared fields andwith_*methods. The caches havecompare=Falseand copies share them. The item compares by value, so "already rendered" isitem == self._renderedand the key tuples are gone. The size goes into a copy of the item (dataclasses.replace), which the handler puts inview_widget.itemwithout the watcher.RequestRendermessage, oneon_request_renderhandler, one threaded exclusiverender_itemworker. The worker catches the errors and postsRenderFailed(source, error, render_id).on_render_failedbranches on the error type and keeps the stale-report drop and the failed-expression retry guard. The item does not holdappnow, andrun_posting_errors,EmptyMessage,ErrorMessage,ExpressionErrorMessage,RequestPlotandRequestImageare removed._render_faileduses the publicreturn_code is not Noneinstead of_exit.exit()sets both.render_canvasandMPLPlot.renderbuild the histogram outside_PLOTEXT_LOCKandRENDER_LOCK. Only the draw holds a lock. The worker installsprogress.cancel_when(...), so a progress report in a cancelled worker raisesprogress.CancelledError(aBaseException, likeasyncio.CancelledError) and the chunked read stops. The worker ignores this exception. New tests check both modes with a slow fake read.warnings.catch_warningsaround the histogram build now. The filters are global for the process, so the build can only change them while it holds the lock. The text path did not suppress these warnings before this change, and the tests run withfilterwarnings = error.ViewWidgethandles the Plot button and the entry box with@on(Button.Pressed,Input.Submitted,Input.Changed).PlotButtonis removed, andPlotInputkeeps only its binding.on_render_faileddrops a report with an old ID. Thus after A → B → A, the error of the cancelled first A render does not replace the new plot. An equal selection uses the running render and keeps its ID, so A → A still shows the error.PlotCanvas) postsResized, andViewWidgetrenders again (debounced). Before, the plot did not render in the smaller pane when the request after the entry box toggle came before the layout (a CI failure oftest_entry_box_rerenders_plot).browser.pyand the__package__workaround are removed.The tests that kept a reference to an item and then read its
sizenow read the item from the view again.Refs #322