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

feat: use multiprocess instead of threads

parent c286e3c8
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import time
from multiprocessing import Queue
import queue
import sys
......@@ -144,7 +145,7 @@ class MeasurementPlot:
plt.rcParams.update({'font.size': 16})
self.data_queue = queue.Queue(10)
self.data_queue = Queue(10)
def stop(self):
self.data_queue.put((None, None, True))
......@@ -160,9 +161,12 @@ class MeasurementPlot:
def drawing_loop(self):
while True:
print('drawing loop getting')
data_frame, pdf_name, stop_thread = self.data_queue.get()
print('drawing loop got. stop is ' +str(stop_thread))
if stop_thread:
return
print('drawing loop drawing')
self.draw_in_this_thread(data_frame, pdf_name='')
def draw_in_this_thread(self, data_frame, pdf_name=''):
......
......@@ -13,7 +13,7 @@ import json
import MeasurementPlot
import sys
import analysis
import threading
from multiprocessing import Process
import external_sensors
import PostPlot
import os
......@@ -174,12 +174,15 @@ class Measurements:
This is a "chamber measurement point". It consists out of multiple measurements sets. The data for all
measurement sets of this chamber point are taken for this measurement.
"""
measurement_thread = threading.Thread(target=self.perform_single_measurement_impl,
args=(output, target_temp, target_hum, soaking_time,
n_stable_reads))
measurement_thread.start()
self.measurement_plot.drawing_loop()
measurement_thread.join()
measurement_process = Process(target=self.perform_single_measurement_impl,
args=(output, target_temp, target_hum, soaking_time, n_stable_reads))
measurement_process.start()
#turn interactive plotting (back) on (is deactivated by starting the process)
plt.ion()
try:
self.measurement_plot.drawing_loop()
finally:
measurement_process.join()
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:
......
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