Skip to content

Commit 4bd80bd

Browse files
Roy-043yorikvanhavre
authored andcommitted
Draft: avoid race condition in todo code
The doTasks function is called multiple times when using Draft tools. In some cases the ToDo.commitlist belonging to a previous call was not fuly processed, resulting in the same list being processed twice. To avoid this the list is stored as a local variable and then immediately reset. Forum topic: https://forum.freecad.org/viewtopic.php?t=91832
1 parent bbb4f26 commit 4bd80bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Mod/Draft/draftutils/todo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def doTasks():
151151
ToDo.itinerary = []
152152

153153
if ToDo.commitlist:
154-
for name, func in ToDo.commitlist:
154+
commit_list = ToDo.commitlist
155+
ToDo.commitlist = [] # Reset immediately to avoid race condition.
156+
for name, func in commit_list:
155157
if _DEBUG_inner:
156158
_msg("Debug: committing.\n"
157159
"name: {}\n".format(name))
@@ -174,7 +176,7 @@ def doTasks():
174176
# Restack Draft screen widgets after creation
175177
if hasattr(Gui, "Snapper"):
176178
Gui.Snapper.restack()
177-
ToDo.commitlist = []
179+
178180

179181
for f, arg in ToDo.afteritinerary:
180182
try:

0 commit comments

Comments
 (0)