From cef8f0ca2e931c87de53b415bf9ae22903cd3911 Mon Sep 17 00:00:00 2001 From: brandon Date: Thu, 22 Feb 2024 22:43:47 -0800 Subject: [PATCH 1/3] changes run_all to return handles to the threads that are spun up that can be used to kill the processes later --- src/glcontrol/runner.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/glcontrol/runner.py b/src/glcontrol/runner.py index b0d18c3..8bc778d 100644 --- a/src/glcontrol/runner.py +++ b/src/glcontrol/runner.py @@ -270,21 +270,15 @@ def _setup_control_loops(self) -> list[ControlLoop]: out.append(new_loop) return out - def run_all(self): + def run_all(self) -> list[threading.Thread]: """Run all the control loops.""" if len(self.control_loops) == 0: logger.warning("No control loops found.") - return - elif len(self.control_loops) == 1: - loop = self.control_loops[0] - loop.run_loop() - return - else: # len(self.control_loops) > 1: + return [] + else: threads = [] for loop in self.control_loops: t = threading.Thread(target=loop.run_loop) threads.append(t) t.start() - for t in threads: - t.join() - # Since some threads should be on loop, we won't ever get here. We may want to handle threads as true daemons where appropriate + return threads \ No newline at end of file From df6db7d987b2b943f172732e23cf74906f299cfb Mon Sep 17 00:00:00 2001 From: brandon Date: Thu, 22 Feb 2024 23:51:36 -0800 Subject: [PATCH 2/3] Provides stop_all function --- src/glcontrol/runner.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/glcontrol/runner.py b/src/glcontrol/runner.py index 8bc778d..8432259 100644 --- a/src/glcontrol/runner.py +++ b/src/glcontrol/runner.py @@ -170,6 +170,12 @@ def run_loop(self): """ raise NotImplementedError("ControlLoop subclasses must implement run_loop") + def stop_loop(self): + """ + Stop the loop. + """ + raise NotImplementedError("ControlLoop subclasses can implement stop_loop") + def _setup_camera(self) -> ImageSourceRT: """ Looks up the image source named in the spec. @@ -270,15 +276,18 @@ def _setup_control_loops(self) -> list[ControlLoop]: out.append(new_loop) return out - def run_all(self) -> list[threading.Thread]: - """Run all the control loops.""" + def run_all(self) -> None: + """Run all the control loops and return""" if len(self.control_loops) == 0: logger.warning("No control loops found.") - return [] else: threads = [] for loop in self.control_loops: t = threading.Thread(target=loop.run_loop) threads.append(t) t.start() - return threads \ No newline at end of file + + def stop_all(self) -> None: + """Stop all the control loops.""" + for loop in self.control_loops: + loop.stop_loop() \ No newline at end of file From 56b26fa584f165d18588edc2fb5bd1831b54f4f4 Mon Sep 17 00:00:00 2001 From: Auto-format Bot Date: Thu, 29 Feb 2024 18:01:48 +0000 Subject: [PATCH 3/3] Automatically reformatting code with black and isort --- src/glcontrol/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glcontrol/runner.py b/src/glcontrol/runner.py index 8432259..beea9ff 100644 --- a/src/glcontrol/runner.py +++ b/src/glcontrol/runner.py @@ -290,4 +290,4 @@ def run_all(self) -> None: def stop_all(self) -> None: """Stop all the control loops.""" for loop in self.control_loops: - loop.stop_loop() \ No newline at end of file + loop.stop_loop()