Skip to content

Commit 3a7481f

Browse files
Merge pull request #6724 from cylc/8.4.x-sync
🤖 Merge 8.4.x-sync into master
2 parents 26f2ac0 + 46f933f commit 3a7481f

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 (
@@ -516,8 +511,11 @@ def update(self, *_):
516511
_, old_node = self.listbox.body.get_focus()
517512

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

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

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

544547
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)