Skip to content

Commit

Permalink
Draft: avoid race condition in todo code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Roy-043 authored and yorikvanhavre committed Nov 7, 2024
1 parent bbb4f26 commit 4bd80bd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Mod/Draft/draftutils/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def doTasks():
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))
Expand All @@ -174,7 +176,7 @@ def doTasks():
# Restack Draft screen widgets after creation
if hasattr(Gui, "Snapper"):
Gui.Snapper.restack()
ToDo.commitlist = []


for f, arg in ToDo.afteritinerary:
try:
Expand Down

0 comments on commit 4bd80bd

Please sign in to comment.