From c0c922536be705e6663c4744792d59b643c8c4ef Mon Sep 17 00:00:00 2001 From: amitlissack Date: Tue, 5 Jan 2021 10:50:37 -0500 Subject: [PATCH] fix(robot-server): ProtocolManager expects a ThreadManager and not a SynchronousAdapter. (#7175) * ProtocolManager expects a ThreadManager and not a SynchronousAdapter. * add typing to ThreadManager.sync --- api/src/opentrons/hardware_control/thread_manager.py | 12 ++++++++---- .../protocol/execution/command_executor.py | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/src/opentrons/hardware_control/thread_manager.py b/api/src/opentrons/hardware_control/thread_manager.py index 061b6212c25..a3ad835e83c 100644 --- a/api/src/opentrons/hardware_control/thread_manager.py +++ b/api/src/opentrons/hardware_control/thread_manager.py @@ -4,7 +4,7 @@ import logging import asyncio import functools -from typing import Generic, TypeVar, Any +from typing import Generic, TypeVar, Any, Optional from .adapters import SynchronousAdapter from .modules.mod_abc import AbstractModule @@ -105,7 +105,7 @@ def __init__(self, builder, *args, **kwargs): self._loop = None self.managed_obj = None self.bridged_obj = None - self._sync_managed_obj = None + self._sync_managed_obj: Optional[SynchronousAdapter] = None is_running = threading.Event() self._is_running = is_running @@ -159,8 +159,12 @@ def _build_and_start_loop(self, builder, *args, **kwargs): loop.close() @property - def sync(self): - return self._sync_managed_obj + def sync(self) -> SynchronousAdapter: + # Why the ignore? + # While self._sync_managed_obj is initialized None, a failure to build + # the managed_obj and _sync_managed_obj is a catastrophic failure. + # All callers of this property assume it to be valid. + return self._sync_managed_obj # type: ignore def __repr__(self): return '' diff --git a/robot-server/robot_server/service/session/session_types/protocol/execution/command_executor.py b/robot-server/robot_server/service/session/session_types/protocol/execution/command_executor.py index 4dabeee0669..fc0830bce1d 100644 --- a/robot-server/robot_server/service/session/session_types/protocol/execution/command_executor.py +++ b/robot-server/robot_server/service/session/session_types/protocol/execution/command_executor.py @@ -89,7 +89,7 @@ def create_worker(configuration: SessionConfiguration, protocol_runner = ProtocolRunner( protocol=protocol, loop=loop, - hardware=configuration.hardware.sync, + hardware=configuration.hardware, motion_lock=configuration.motion_lock) # The async worker to which all commands are delegated. return _Worker(