From d7f76215098d0623bcaaf68b407c3a562e5f259a Mon Sep 17 00:00:00 2001 From: kwagyeman <5694981+kwagyeman@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:14:42 -0800 Subject: [PATCH] camera: Let stop() and exec() wait for the script with no default timeout. stop() waits for the running script to exit for as long as it takes unless a timeout is given, and exec() forwards its timeout to stop(). A dead link is still bounded by the transport timeout and resync. --- src/openmv/camera.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/openmv/camera.py b/src/openmv/camera.py index 414fb19..97e7114 100644 --- a/src/openmv/camera.py +++ b/src/openmv/camera.py @@ -331,23 +331,30 @@ def update_capabilities(self): @retry_if_failed def stop(self, timeout=None): - """Stop running script and wait for it to exit""" + """Stop running script and wait for it to exit. + + timeout is how long to wait for the script to exit; None waits + for as long as it takes. + """ # Stop running script stdin_id = self.get_channel(name="stdin") self._channel_ioctl(stdin_id, ChannelIOCTL.STDIN_STOP) # Wait for the script to exit - timeout = self.timeout if timeout is None else timeout start_time = time.time() while self.read_status()["stdin"]: - if time.time() - start_time > timeout: + if timeout is not None and time.time() - start_time > timeout: raise TimeoutException("Timeout waiting for the script to stop") @retry_if_failed - def exec(self, script): - """Write and execute a script""" + def exec(self, script, timeout=None): + """Write and execute a script. + + A running script is stopped first; timeout is how long to wait for + it to exit (None waits for as long as it takes). + """ # Stop the running script first if self.read_status()["stdin"]: - self.stop() + self.stop(timeout=timeout) stdin_id = self.get_channel(name="stdin") # Reset script buffer self._channel_ioctl(stdin_id, ChannelIOCTL.STDIN_RESET)