From 23c278ef9f542c5c8f2bc7d4f0428990fbca205c Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Thu, 5 Nov 2026 17:22:34 +0300 Subject: [PATCH] The setup window waits at most 1.5 seconds for the recorded paths A recorded path on a disconnected network share can block its stat call. The paths load in a daemon thread and nothing is prefilled when it has not returned in time. Co-Authored-By: Claude Opus 5.5 --- installer/gui.py | 15 ++++++++++++++- tests/installer_gui_test.py | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/installer/gui.py b/installer/gui.py index d3cbd498..2c89ec78 100644 --- a/installer/gui.py +++ b/installer/gui.py @@ -17,6 +17,7 @@ import os import subprocess import sys import tempfile +import threading from pathlib import Path from . import dpi @@ -46,6 +47,18 @@ COLOR = {PENDING: '#808080', RUNNING: '#1a5fb4', DONE: '#26a269', SKIPPED: '#808 PAD = dpi.px(14) # padding of the window and its frames WRAP = dpi.px(620) # wrap width of the long labels +RECENT_WAIT = 1.5 # seconds the window waits for the recorded paths + + +def load_recent(wait=RECENT_WAIT): + """recent.load() in a daemon thread, waited for at most `wait` seconds: a recorded path on a disconnected network + share can block its stat call for a long time. Nothing is prefilled when it has not returned by then.""" + out = {} + thread = threading.Thread(target=lambda: out.update(recent.load()), daemon=True) + thread.start() + thread.join(wait) + return {} if thread.is_alive() else out + def fix_tcl_paths(): """The embeddable Python keeps Tcl/Tk next to python.exe (python/tcl); point Tcl at it when it is not found.""" @@ -119,7 +132,7 @@ class App: # recorded sources fill only empty fields; dest goes last, its trace runs refresh_form (update hint and # recorded language). In update mode filled files are harmless: Extract.current hashes one only when its # size or mtime differ from the recorded ones. - last = recent.load() + last = load_recent() for name in ('base', 'update', 'keys', 'firmware', 'dest'): if name in last and not self.vars[name].get().strip(): self.vars[name].set(last[name]) diff --git a/tests/installer_gui_test.py b/tests/installer_gui_test.py index 16e0cbc1..3d2a370d 100644 --- a/tests/installer_gui_test.py +++ b/tests/installer_gui_test.py @@ -31,6 +31,10 @@ sys.path.insert(0, str(ROOT)) from installer import layout as layouts # noqa: E402 from installer import dpi # noqa: E402 from installer import recent # noqa: E402 +try: + from installer import gui # noqa: E402 +except ImportError: # no tkinter + gui = None from installer import state as statefile # noqa: E402 from installer.events import Reporter # noqa: E402 from installer.runner import Context # noqa: E402 @@ -500,6 +504,18 @@ class RecentTest(unittest.TestCase): self.file.write_text(text, encoding='utf-8') self.assertEqual(recent.load(), {}, text) + @unittest.skipIf(gui is None, 'no tkinter') + def test_blocking_load_leaves_fields_empty(self): + with unittest.mock.patch.object(recent, 'load', side_effect=lambda: time.sleep(5) or {'dest': 'x'}): + start = time.monotonic() + self.assertEqual(gui.load_recent(0.3), {}) + self.assertLess(time.monotonic() - start, 2) + + @unittest.skipIf(gui is None, 'no tkinter') + def test_fast_load_is_returned(self): + with unittest.mock.patch.object(recent, 'load', return_value={'dest': 'x'}): + self.assertEqual(gui.load_recent(), {'dest': 'x'}) + class SmokeTest(unittest.TestCase): def test_every_screen_in_both_languages(self):