diff --git a/sbot/robot.py b/sbot/robot.py index f002ede..22e8ec6 100644 --- a/sbot/robot.py +++ b/sbot/robot.py @@ -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(), [])) @@ -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)