Skip to content

Commit ba7be80

Browse files
try except to handle pwm chips keep changing, fix export
1 parent 1f30ad2 commit ba7be80

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

pioreactor/actions/leader/export_experiment_data.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def export_experiment_data(
185185

186186
_partition_by_unit = dataset.has_unit and (partition_by_unit or dataset.always_partition_by_unit)
187187
_partition_by_experiment = dataset.has_experiment and partition_by_experiment
188-
filenames: list[str] = []
188+
path_to_files: list[Path] = []
189189
placeholders: dict[str, str] = {}
190190

191191
order_by_col = dataset.default_order_by
@@ -243,15 +243,17 @@ def export_experiment_data(
243243
)
244244

245245
if rows_partition not in parition_to_writer_map:
246+
# create a new csv writer for this partition since it doesn't exist yet
246247
filename = f"{dataset_name}-" + "-".join(rows_partition) + f"-{time}.csv"
247248
filename = filename.replace(" ", "_")
248-
filenames.append(filename)
249-
path_to_file = Path(Path(output).parent / filename)
249+
path_to_file = Path(output).parent / filename
250250
parition_to_writer_map[rows_partition] = csv.writer(
251251
stack.enter_context(open(path_to_file, "w")), delimiter=","
252252
)
253253
parition_to_writer_map[rows_partition].writerow(headers)
254254

255+
path_to_files.append(path_to_file)
256+
255257
parition_to_writer_map[rows_partition].writerow(row)
256258

257259
if count % 10_000 == 0:
@@ -262,10 +264,9 @@ def export_experiment_data(
262264
logger.warning(f"No data present in {dataset_name}. Check database?")
263265

264266
zf.mkdir(dataset_name)
265-
for filename in filenames:
266-
path_to_file = Path(output, filename)
267+
for path_to_file in path_to_files:
267268
zf.write(path_to_file, arcname=f"{dataset_name}/{filename}")
268-
Path(path_to_file).unlink()
269+
path_to_file.unlink()
269270

270271
logger.info("Finished export.")
271272
return

pioreactor/utils/pwm.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pioreactor.types import GpioPin
2020
from pioreactor.utils import clamp
2121
from pioreactor.utils import local_intermittent_storage
22-
from pioreactor.version import rpi_version_info
2322
from pioreactor.whoami import get_assigned_experiment_name
2423
from pioreactor.whoami import get_unit_name
2524
from pioreactor.whoami import is_testing_env
@@ -29,6 +28,7 @@
2928
from pioreactor.utils.mock import MockHardwarePWM as HardwarePWM
3029
else:
3130
from rpi_hardware_pwm import HardwarePWM # type: ignore
31+
from rpi_hardware_pwm import HardwarePWMException # type: ignore
3232

3333

3434
class HardwarePWMOutputDevice(HardwarePWM):
@@ -41,10 +41,12 @@ def __init__(self, pin: GpioPin, frequency: float = 100) -> None:
4141

4242
pwm_channel = self.HARDWARE_PWM_CHANNELS[pin]
4343

44-
if rpi_version_info.startswith("Raspberry Pi 5"):
44+
try:
45+
super().__init__(
46+
pwm_channel, hz=frequency
47+
) # default is chip=0 for all except RPi5 on Kernel 6.6 (which is 2)
48+
except HardwarePWMException:
4549
super().__init__(pwm_channel, hz=frequency, chip=2)
46-
else:
47-
super().__init__(pwm_channel, hz=frequency) # default is chip=0
4850

4951
def start(self, initial_dc: pt.FloatBetween0and100) -> None:
5052
self._started = True

0 commit comments

Comments
 (0)