Skip to content

Commit

Permalink
nest thread initialization inside try-except block
Browse files Browse the repository at this point in the history
  • Loading branch information
mslaffin committed Dec 6, 2024
1 parent ce121ee commit c3303ae
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions instrumentctl/E5CN_modbus/E5CN_modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@ def __init__(self, port, baudrate=9600, timeout=1, parity='E', stopbits=2, bytes

def start_reading_temperatures(self):
"""Start threads for continuously reading temperature for each unit."""
for unit in self.UNIT_NUMBERS:
thread = threading.Thread(target=self._read_temperature_continuously, args=(unit,), daemon=True)
thread.start()
self.threads.append(thread)
try:
for unit in self.UNIT_NUMBERS:
thread = threading.Thread(
target=self._read_temperature_continuously,
args=(unit,),
daemon=True
)
thread.start()
self.threads.append(thread)
return True
except Exception as e:
self.log(f"Failed to start CCS temperature reading threads: {str(e)}", LogLevel.ERROR)
return False

def _read_temperature_continuously(self, unit):
"""
Expand Down

0 comments on commit c3303ae

Please sign in to comment.