From 16f419d53adbcf009483cb9941de9eb96110340c Mon Sep 17 00:00:00 2001 From: David Foster Date: Tue, 26 Sep 2023 08:56:47 -0400 Subject: [PATCH] RootTask: Guard against unsynchronized access to RootTask.children --- src/crystal/task.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/crystal/task.py b/src/crystal/task.py index 7130a3c6..fad07906 100644 --- a/src/crystal/task.py +++ b/src/crystal/task.py @@ -257,7 +257,6 @@ def append_child(self, child: Task, *, already_complete_ok: bool=False) -> None: def finish(self) -> None: """ Marks this task as completed. - Threadsafe. """ # Mark as complete immediately, because caller may check this task's complete status self._complete = True @@ -1310,6 +1309,12 @@ def __init__(self): super().__init__(title='ROOT') self.subtitle = 'Running' + @property # type: ignore[misc] + @fg_affinity # force any access to synchronize with foreground thread + @overrides + def children(self) -> List[Task]: + return super().children + @overrides def append_child(self, child: Task, *args, **kwargs) -> None: """