Skip to content

Commit

Permalink
Use the timeserver connection as the lock in the simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed May 23, 2024
1 parent bba7cd4 commit 9e9e226
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sbot/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ def __init__(
trace_logging: bool = False,
manual_boards: dict[str, list[str]] | None = None,
) -> None:
self._lock = obtain_lock()
if IN_SIMULATOR:
self._lock = TimeServer.initialise()
if self._lock is None:
raise OSError('Unable to obtain lock, Is another robot instance already running?')
else:
self._lock = obtain_lock()
self._metadata: Metadata | None = None

setup_logging(debug, trace_logging)
ensure_atexit_on_term()

logger.info(f"SourceBots API v{__version__}")
if IN_SIMULATOR:
self._time_server = TimeServer.initialise()
else:
self._time_server = None

if manual_boards:
self._init_power_board(manual_boards.get(PowerBoard.get_board_type(), []))
Expand Down Expand Up @@ -255,7 +256,8 @@ def sleep(self, secs: float) -> None:
:param secs: The number of seconds to sleep for
"""
if IN_SIMULATOR:
self._time_server.sleep(secs)
assert isinstance(self._lock, TimeServer)
self._lock.sleep(secs)
else:
sleep(secs)

Expand Down

0 comments on commit 9e9e226

Please sign in to comment.