Remove sleeps that cause delays exiting thread
What changed, and why it matters
This commit refactors how a scrolling text display pauses at the start and end of a line. Previously the code simply slept (paused) the entire thread, which made it slow to respond when the user wanted to stop scrolling. The new code tracks pause timing with variables and checks them in the main loop, so the thread can exit promptly when asked. There is no security issue visible in this change.
No security action required. Treat as a normal UI responsiveness improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In seedsigner/gui/components.py, the TextArea scrolling thread is rewritten to avoid blocking time.sleep() calls while holding at the left/right scroll extents. Instead of sleeping during begin_hold_secs/end_hold_secs, it now records hold_started_at and cur_hold_duration, then each loop iteration checks whether the hold has elapsed before continuing. This allows self.keep_running and self.scrolling_active checks to be evaluated every 0.1 s during a hold, so the thread exits faster when stop_scrolling() is called. The change is a responsiveness/UX improvement, not a security fix.
Changed components
src/seedsigner/gui/components.py:TextArea scrolling threadInspect captured patch +33 / −11
diff --git a/src/seedsigner/gui/components.py b/src/seedsigner/gui/components.py
index d9a2e0b..ac0805c 100644
--- a/src/seedsigner/gui/components.py
+++ b/src/seedsigner/gui/components.py
@@ -623,7 +623,7 @@ class TextArea(BaseComponent):
self.horizontal_scroll_position = 0
self.scroll_increment_sign = 1 # flip to negative to scroll text to the right
- self.renderer = Renderer.get_instance()
+ self.renderer = Renderer.get_instance()
def stop_scrolling(self):
@@ -645,11 +645,23 @@ class TextArea(BaseComponent):
"""
max_scroll = self.rendered_text_img.width - self.visible_width
+ # The scrolling holds / pauses at the start and end of the text line. These
+ # vars track when we started holding and how long we should hold.
+ hold_started_at = None
+ cur_hold_duration = None
+
while self.keep_running:
if not self.scrolling_active:
time.sleep(0.1)
continue
+ if cur_hold_duration:
+ hold_time_elapsed = time.time() - hold_started_at
+ if hold_time_elapsed < cur_hold_duration:
+ # Still holding; skip scrolling logic
+ time.sleep(0.1)
+ continue
+
with self.renderer.lock:
if not self.scrolling_active:
# We were stopped while waiting for the lock
@@ -659,30 +671,40 @@ class TextArea(BaseComponent):
self.renderer.canvas.paste(img, (self.screen_x, self.screen_y - self.scroll_y))
self.renderer.show_image()
- if self.horizontal_scroll_position == 0:
- # Pause on initial (left-justified) position...
- time.sleep(self.begin_hold_secs)
+ if hold_started_at is not None:
+ # If we're here, we've held long enough; reset the vars and resume
+ # scrolling.
+ hold_started_at = None
+ cur_hold_duration = None
- # Don't count those pause seconds
- last_render_time = None
+ elif self.horizontal_scroll_position == 0:
+ # Pause on initial (left-justified) position...
+ hold_started_at = time.time()
+ cur_hold_duration = self.begin_hold_secs
- # Scroll the text left
+ # Next scroll direction will be left
self.scroll_increment_sign = 1
+ # Don't count those pause seconds
+ last_render_time = None
+ continue
+
elif self.horizontal_scroll_position == max_scroll:
# ...and slight pause at end of scroll
- time.sleep(self.end_hold_secs)
+ hold_started_at = time.time()
+ cur_hold_duration = self.end_hold_secs
# Don't count those pause seconds
last_render_time = None
- # Scroll the text right
+ # Scroll will be to the right
self.scroll_increment_sign = -1
-
+ continue
+
else:
# No need to CPU limit when running in its own thread?
time.sleep(0.02)
-
+
next_render_time = time.time()
if not last_render_time:
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.