Skip to content
Snippets Groups Projects
Commit d5d6fffb authored by Martin Killenberg's avatar Martin Killenberg
Browse files

fix: cannot pickle real devices

Solution: use plotting as inner process
parent 365c13ae
No related branches found
No related tags found
No related merge requests found
......@@ -161,17 +161,19 @@ class MeasurementPlot:
except queue.Full:
pass
def drawing_loop(self):
def drawing_loop(self, stop_measurement_event):
# turn interactive plotting (back) on (is deactivated by starting the process)
plt.ion()
while True:
data_frame, pdf_name, stop_drawing = self.data_queue.get()
if stop_drawing:
return
try:
if not process_sync.stop_measurement.is_set():
if not stop_measurement_event.is_set():
self.draw_in_this_thread(data_frame, pdf_name='')
except Exception as e:
# Don't exit here. Always drain the data queue so the program can terminate correctly
process_sync.stop_measurement.set()
stop_measurement_event.set()
def draw_in_this_thread(self, data_frame, pdf_name=''):
timestamps = data_frame.TIMESTAMP
......
......@@ -177,17 +177,13 @@ class Measurements:
"""
process_sync.stop_measurement.clear()
ctx = mp.get_context('spawn')
measurement_process = ctx.Process(target=self.perform_single_measurement_impl,
args=(output, target_temp, target_hum, soaking_time, n_stable_reads,
process_sync.stop_measurement))
measurement_process.start()
# turn interactive plotting (back) on (is deactivated by starting the process)
plt.ion()
self.measurement_plot.drawing_loop()
measurement_process.join()
plot_process = ctx.Process(target=self.measurement_plot.drawing_loop,
args=(process_sync.stop_measurement,))
plot_process.start()
self.perform_single_measurement_impl(output, target_temp, target_hum, soaking_time, n_stable_reads)
plot_process.join()
def perform_single_measurement_impl(self, output, target_temp, target_hum, soaking_time, n_stable_reads,
stop_measurement):
def perform_single_measurement_impl(self, output, target_temp, target_hum, soaking_time, n_stable_reads):
with open(output, mode='w', newline='') as csv_file:
......@@ -219,7 +215,7 @@ class Measurements:
dut_signal_queues = [[], []]
while True:
if stop_measurement.is_set():
if process_sync.stop_measurement.is_set():
do_another_measurement = False
break
......@@ -282,7 +278,7 @@ class Measurements:
all_measurements_stable = True
for i in range(0, n_stable_reads):
if stop_measurement.is_set():
if process_sync.stop_measurement.is_set():
all_measurements_stable = False #not enough stable reads yet
do_another_measurement = False
break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment