forked from awendt/pyrelacs
[app] starting repos with as a thread
This commit is contained in:
parent
cb5c08bc94
commit
cd6bc0dc04
@ -93,6 +93,21 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
def run_repro(self, n, fn):
|
||||
self.text.appendPlainText(f"started Repro {n}, {fn}")
|
||||
worker = Worker(self.repros.run_repro, n, fn)
|
||||
worker.signals.result.connect(self.print_output)
|
||||
worker.signals.finished.connect(self.thread_complete)
|
||||
worker.signals.progress.connect(self.progress_fn)
|
||||
|
||||
self.threadpool.start(worker)
|
||||
|
||||
def print_output(self, s):
|
||||
print(s)
|
||||
|
||||
def thread_complete(self):
|
||||
print("THREAD COMPLETE!")
|
||||
|
||||
def progress_fn(self, n):
|
||||
print("%d%% done" % n)
|
||||
|
||||
|
||||
def main():
|
||||
@ -114,7 +129,7 @@ def main():
|
||||
window.resize(width, height)
|
||||
window.move(x, y)
|
||||
window.show()
|
||||
app.exec()
|
||||
exit_code = app.exec()
|
||||
|
||||
# store window position and size
|
||||
pos = window.pos()
|
||||
@ -126,4 +141,5 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
|
@ -25,12 +25,10 @@ class Calibration(MccDac):
|
||||
self.AMPLITUDE = 1
|
||||
self.SINFREQ = 750
|
||||
|
||||
def run(self):
|
||||
|
||||
def segfault_handler(self, signum, frame):
|
||||
print(f"Segmentation fault caught! Signal number: {signum}")
|
||||
self.disconnect_dac()
|
||||
sys.exit(1) # Gracefully exit the program
|
||||
@staticmethod
|
||||
def run():
|
||||
calb = Calibration()
|
||||
calb.check_beat()
|
||||
|
||||
def check_amplitude(self):
|
||||
db_values = [0.0, -5.0, -10.0, -20.0, -50.0]
|
||||
@ -53,7 +51,10 @@ class Calibration(MccDac):
|
||||
)
|
||||
|
||||
data_channel_one = self.read_analog(
|
||||
[0, 0], self.DURATION, self.SAMPLERATE, ScanOption=uldaq.ScanOption.EXTTRIGGER
|
||||
[0, 0],
|
||||
self.DURATION,
|
||||
self.SAMPLERATE,
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
)
|
||||
time.sleep(1)
|
||||
|
||||
@ -107,7 +108,6 @@ class Calibration(MccDac):
|
||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||
)
|
||||
self.diggital_trigger()
|
||||
signal.signal(signal.SIGSEGV, self.segfault_handler)
|
||||
log.info(self.ao_device)
|
||||
ai_status = uldaq.ScanStatus.RUNNING
|
||||
ao_status = uldaq.ScanStatus.RUNNING
|
||||
|
@ -1,15 +1,34 @@
|
||||
import sys
|
||||
import importlib.util
|
||||
import ast
|
||||
import pathlib
|
||||
|
||||
from IPython import embed
|
||||
from pyrelacs.util.logging import config_logging
|
||||
|
||||
log = config_logging()
|
||||
|
||||
|
||||
class Repro:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def run_repro(self, name: str, *args, **kwargs) -> None:
|
||||
pass
|
||||
def run_repro(self, name: str, file: pathlib.Path, *args, **kwargs) -> None:
|
||||
spec = importlib.util.spec_from_file_location("rep", file)
|
||||
if not spec:
|
||||
log.error("Could not load the repro")
|
||||
else:
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
if not module:
|
||||
log.error("Could not load Class of the repro")
|
||||
else:
|
||||
sys.modules[name] = module
|
||||
spec.loader.exec_module(module)
|
||||
if hasattr(module, name):
|
||||
rep_class = getattr(module, name)
|
||||
rep_class.run()
|
||||
else:
|
||||
raise AttributeError(f"{name} has no run function")
|
||||
|
||||
def names_of_repros(self):
|
||||
file_path_cur = pathlib.Path(__file__).parent
|
||||
|
Loading…
Reference in New Issue
Block a user