diff --git a/api/src/opentrons/hardware_control/api.py b/api/src/opentrons/hardware_control/api.py index 4b62eba7e3ab..7267281b2477 100644 --- a/api/src/opentrons/hardware_control/api.py +++ b/api/src/opentrons/hardware_control/api.py @@ -431,7 +431,9 @@ def has_gripper(self) -> bool: return False async def cache_instruments( - self, require: Optional[Dict[top_types.Mount, PipetteName]] = None + self, + require: Optional[Dict[top_types.Mount, PipetteName]] = None, + skip_if_would_block: bool = False, ) -> None: """ Scan the attached instruments, take necessary configuration actions, diff --git a/api/src/opentrons/hardware_control/ot3api.py b/api/src/opentrons/hardware_control/ot3api.py index 2190f1b5c4d1..ced88815ec94 100644 --- a/api/src/opentrons/hardware_control/ot3api.py +++ b/api/src/opentrons/hardware_control/ot3api.py @@ -653,12 +653,16 @@ def get_all_attached_instr(self) -> Dict[OT3Mount, Optional[InstrumentDict]]: # TODO (spp, 2023-01-31): add unit tests async def cache_instruments( - self, require: Optional[Dict[top_types.Mount, PipetteName]] = None + self, + require: Optional[Dict[top_types.Mount, PipetteName]] = None, + skip_if_would_block: bool = False, ) -> None: """ Scan the attached instruments, take necessary configuration actions, and set up hardware controller internal state if necessary. """ + if skip_if_would_block and self._motion_lock.locked(): + return async with self._motion_lock: skip_configure = await self._cache_instruments(require) if not skip_configure or not self._configured_since_update: diff --git a/api/src/opentrons/hardware_control/protocols/instrument_configurer.py b/api/src/opentrons/hardware_control/protocols/instrument_configurer.py index 810caad667b4..ab5b37acc99b 100644 --- a/api/src/opentrons/hardware_control/protocols/instrument_configurer.py +++ b/api/src/opentrons/hardware_control/protocols/instrument_configurer.py @@ -28,6 +28,7 @@ def reset_instrument(self, mount: Optional[MountArgType] = None) -> None: async def cache_instruments( self, require: Optional[Dict[Mount, PipetteName]] = None, + skip_if_would_block: bool = False, ) -> None: """ Scan the attached instruments, take necessary configuration actions, diff --git a/robot-server/robot_server/instruments/router.py b/robot-server/robot_server/instruments/router.py index f8e7448d5f1f..8ee055d98d48 100644 --- a/robot-server/robot_server/instruments/router.py +++ b/robot-server/robot_server/instruments/router.py @@ -216,7 +216,7 @@ async def _get_attached_instruments_ot3( hardware: OT3HardwareControlAPI, ) -> PydanticResponse[SimpleMultiBody[AttachedItem]]: # OT3 - await hardware.cache_instruments() + await hardware.cache_instruments(skip_if_would_block=True) response_data = await _get_instrument_data(hardware) return await PydanticResponse.create( content=SimpleMultiBody.construct(