aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2023-11-20 19:43:36 -0500
committerKevin O'Connor <kevin@koconnor.net>2023-11-28 21:24:41 -0500
commit03f69cd81a129456a66e2deb03bc8b137504c179 (patch)
tree7d3aac3595c165a02a540643a4beb76bf21a4f8e
parentea2f6bc0f544132738c7f052ffcc586fa884a19a (diff)
downloadkutter-03f69cd81a129456a66e2deb03bc8b137504c179.tar.gz
kutter-03f69cd81a129456a66e2deb03bc8b137504c179.tar.xz
kutter-03f69cd81a129456a66e2deb03bc8b137504c179.zip
tmc: Query latest value during _init_registers()
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 <kevin@koconnor.net>
-rw-r--r--klippy/extras/tmc.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/klippy/extras/tmc.py b/klippy/extras/tmc.py
index c3ece070..8143882a 100644
--- a/klippy/extras/tmc.py
+++ b/klippy/extras/tmc.py
@@ -262,7 +262,8 @@ class TMCCommandHelper:
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):