Skip to content

Commit

Permalink
tmc: Query latest value during _init_registers()
Browse files Browse the repository at this point in the history
The set_register() code may block, and it therefore may be possible
that the loop in _init_registers() could occur in parallel with other
updates.  That could result in a "OrderedDict mutated during
iteration" error.

Avoid the error by querying the latest value during each iteration of
the loop.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Nov 29, 2023
1 parent ea2f6bc commit 03f69cd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion klippy/extras/tmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def __init__(self, config, mcu_tmc, current_helper):
desc=self.cmd_SET_TMC_CURRENT_help)
def _init_registers(self, print_time=None):
# Send registers
for reg_name, val in self.fields.registers.items():
for reg_name in list(self.fields.registers.keys()):
val = self.fields.registers[reg_name] # Val may change during loop
self.mcu_tmc.set_register(reg_name, val, print_time)
cmd_INIT_TMC_help = "Initialize TMC stepper driver registers"
def cmd_INIT_TMC(self, gcmd):
Expand Down

0 comments on commit 03f69cd

Please sign in to comment.