Skip to content

Commit

Permalink
Merge pull request #427 from LedgerHQ/fix/api
Browse files Browse the repository at this point in the history
[B2CA-1417] The Speculos API is not properly stopped when Speculos quits
  • Loading branch information
lpascal-ledger authored Oct 12, 2023
2 parents bced779 + 3ef5482 commit 5ac7327
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions speculos/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions speculos/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5ac7327

Please sign in to comment.