diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cce73ed..3e475741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.2] - 2023-09-28 + +### Fixed +- API: the API thread is asked to stop when Speculos exits ## [0.3.1] - 2023-09-28 diff --git a/speculos/api/api.py b/speculos/api/api.py index 5e455ae0..7192d148 100644 --- a/speculos/api/api.py +++ b/speculos/api/api.py @@ -30,6 +30,7 @@ def __init__(self, api_port: int) -> None: self._notify_exit: socket.socket self.sock, self._notify_exit = socket.socketpair() self.api_port: int = api_port + self._api_thread: threading.Thread @property def file(self): @@ -55,8 +56,11 @@ def start_server_thread(self, automation_server: BroadcastInterface) -> None: wrapper = ApiWrapper(screen_, seph_, automation_server) self._app = wrapper.app - api_thread = threading.Thread(target=self._run, name="API-server", daemon=True) - api_thread.start() + self._api_thread = threading.Thread(target=self._run, name="API-server", daemon=True) + self._api_thread.start() + + def stop(self): + self._api_thread.join(10) class ApiWrapper: diff --git a/speculos/main.py b/speculos/main.py index 3eb88541..0b80b42c 100644 --- a/speculos/main.py +++ b/speculos/main.py @@ -520,6 +520,9 @@ def main(prog=None) -> int: screen_notifier.run() + if apirun is not None: + apirun.stop() + s2.close() _, status = os.waitpid(qemu_pid, 0) qemu_exit_status = os.WEXITSTATUS(status)