Skip to content

Commit 46f933f

Browse files
authored
Merge pull request #6722 from oliver-sanders/tui-memory-leak
Tui memory leak
2 parents 1c5bcd7 + d9919ee commit 46f933f

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

changes.d/6722.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a slow memory leak in Tui.

cylc/flow/tui/app.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@
2222
import re
2323

2424
import urwid
25-
try:
26-
from urwid.widget import SelectableIcon
27-
except ImportError:
28-
# BACK COMPAT: urwid.wimp
29-
# From: urwid 2.0
30-
# To: urwid 2.2
31-
from urwid.wimp import SelectableIcon
25+
from urwid.canvas import CanvasCache
26+
from urwid.widget import SelectableIcon
3227

3328
from cylc.flow.id import Tokens
3429
from cylc.flow.task_state import (
@@ -515,8 +510,11 @@ def update(self, *_):
515510
_, old_node = self.listbox.body.get_focus()
516511

517512
# nuke the tree
518-
self.tree_walker = urwid.TreeWalker(topnode)
519-
self.listbox.body = self.tree_walker
513+
if not (self.tree_walker):
514+
self.tree_walker = urwid.TreeWalker(topnode)
515+
self.listbox.body = self.tree_walker
516+
else:
517+
self.tree_walker.set_focus(topnode)
520518

521519
# get the new focus
522520
_, new_node = self.listbox.body.get_focus()
@@ -538,6 +536,11 @@ def update(self, *_):
538536
if self.loop:
539537
self.loop.set_alarm_in(self.UPDATE_INTERVAL, self.update)
540538

539+
# NOTE: prevent a memory leak by clearing out any caches that urwid
540+
# may have accumulated for the previous TuiNode instance
541+
# (and its child widgets)
542+
CanvasCache.clear()
543+
541544
return True
542545

543546
def filter_by_task_state(self, filtered_state=None):

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ install_requires =
7676
pyzmq>=22
7777
importlib_metadata>=5.0; python_version < "3.12"
7878
# NOTE: exclude two urwid versions that were not compatible with Tui
79-
urwid==2.*,!=2.6.2,!=2.6.3
79+
urwid>=2.2,!=2.6.2,!=2.6.3,<3
8080
# unpinned transient dependencies used for type checking
8181
rx
8282
promise

0 commit comments

Comments
 (0)