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):
|
def run_repro(self, n, fn):
|
||||||
self.text.appendPlainText(f"started Repro {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():
|
def main():
|
||||||
@ -114,7 +129,7 @@ def main():
|
|||||||
window.resize(width, height)
|
window.resize(width, height)
|
||||||
window.move(x, y)
|
window.move(x, y)
|
||||||
window.show()
|
window.show()
|
||||||
app.exec()
|
exit_code = app.exec()
|
||||||
|
|
||||||
# store window position and size
|
# store window position and size
|
||||||
pos = window.pos()
|
pos = window.pos()
|
||||||
@ -127,3 +142,4 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@ -25,12 +25,10 @@ class Calibration(MccDac):
|
|||||||
self.AMPLITUDE = 1
|
self.AMPLITUDE = 1
|
||||||
self.SINFREQ = 750
|
self.SINFREQ = 750
|
||||||
|
|
||||||
def run(self):
|
@staticmethod
|
||||||
|
def run():
|
||||||
def segfault_handler(self, signum, frame):
|
calb = Calibration()
|
||||||
print(f"Segmentation fault caught! Signal number: {signum}")
|
calb.check_beat()
|
||||||
self.disconnect_dac()
|
|
||||||
sys.exit(1) # Gracefully exit the program
|
|
||||||
|
|
||||||
def check_amplitude(self):
|
def check_amplitude(self):
|
||||||
db_values = [0.0, -5.0, -10.0, -20.0, -50.0]
|
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(
|
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)
|
time.sleep(1)
|
||||||
|
|
||||||
@ -107,7 +108,6 @@ class Calibration(MccDac):
|
|||||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||||
)
|
)
|
||||||
self.diggital_trigger()
|
self.diggital_trigger()
|
||||||
signal.signal(signal.SIGSEGV, self.segfault_handler)
|
|
||||||
log.info(self.ao_device)
|
log.info(self.ao_device)
|
||||||
ai_status = uldaq.ScanStatus.RUNNING
|
ai_status = uldaq.ScanStatus.RUNNING
|
||||||
ao_status = uldaq.ScanStatus.RUNNING
|
ao_status = uldaq.ScanStatus.RUNNING
|
||||||
|
@ -1,15 +1,34 @@
|
|||||||
|
import sys
|
||||||
|
import importlib.util
|
||||||
import ast
|
import ast
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
|
from pyrelacs.util.logging import config_logging
|
||||||
|
|
||||||
|
log = config_logging()
|
||||||
|
|
||||||
|
|
||||||
class Repro:
|
class Repro:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_repro(self, name: str, *args, **kwargs) -> None:
|
def run_repro(self, name: str, file: pathlib.Path, *args, **kwargs) -> None:
|
||||||
pass
|
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):
|
def names_of_repros(self):
|
||||||
file_path_cur = pathlib.Path(__file__).parent
|
file_path_cur = pathlib.Path(__file__).parent
|
||||||
|
Loading…
Reference in New Issue
Block a user