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
This commit is contained in:
Roy-043
2024-11-06 11:32:55 +01:00
committed by Yorik van Havre
parent bbb4f2664e
commit 4bd80bdcbb

View File

@@ -151,7 +151,9 @@ class ToDo:
ToDo.itinerary = []
if ToDo.commitlist:
for name, func in ToDo.commitlist:
commit_list = ToDo.commitlist
ToDo.commitlist = [] # Reset immediately to avoid race condition.
for name, func in commit_list:
if _DEBUG_inner:
_msg("Debug: committing.\n"
"name: {}\n".format(name))
@@ -174,7 +176,7 @@ class ToDo:
# Restack Draft screen widgets after creation
if hasattr(Gui, "Snapper"):
Gui.Snapper.restack()
ToDo.commitlist = []
for f, arg in ToDo.afteritinerary:
try: