Skip to content

Commit

Permalink
An idea...
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Nov 8, 2024
1 parent 9d24842 commit ff016ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/ophyd_async/core/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def create_children_from_annotations(self, device: Device):
during ``__init__``.
"""

async def connect_mock(self, device: Device, mock: LazyMock):
def connect_mock(self, device: Device, mock: LazyMock):
# Connect serially, no errors to gather up as in mock mode
for name, child_device in device.children():
await child_device.connect(mock=mock.child(name))
assert not child_device.connect(mock=mock.child(name))

async def connect_real(self, device: Device, timeout: float, force_reconnect: bool):
"""Used during ``Device.connect``.
Expand Down Expand Up @@ -123,12 +123,12 @@ def __setattr__(self, name: str, value: Any) -> None:
# Avoid the super call as this happens a lot
return object.__setattr__(self, name, value)

async def connect(
def connect(
self,
mock: bool | LazyMock = False,
timeout: float = DEFAULT_TIMEOUT,
force_reconnect: bool = False,
) -> None:
) -> asyncio.Task | None:
"""Connect self and all child Devices.
Contains a timeout that gets propagated to child.connect methods.
Expand All @@ -148,7 +148,7 @@ async def connect(
elif not self._mock:
# Make one
self._mock = LazyMock()
await self._connector.connect_mock(self, self._mock)
self._connector.connect_mock(self, self._mock)
else:
# Try to cache the connect in real mode
can_use_previous_connect = (
Expand All @@ -162,7 +162,7 @@ async def connect(
self._connect_task = asyncio.create_task(coro)
assert self._connect_task, "Connect task not created, this shouldn't happen"
# Wait for it to complete
await self._connect_task
return self._connect_task


_not_device_attrs = {
Expand Down
2 changes: 1 addition & 1 deletion src/ophyd_async/core/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SignalConnector(DeviceConnector):
def __init__(self, backend: SignalBackend):
self.backend = self._init_backend = backend

async def connect_mock(self, device: Device, mock: LazyMock):
def connect_mock(self, device: Device, mock: LazyMock):
self.backend = MockSignalBackend(self._init_backend, mock)

async def connect_real(self, device: Device, timeout: float, force_reconnect: bool):
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def __init__(self, name: str) -> None:

async def test_many_individual_device_connects_not_slow():
start = time.time()
for i in range(100):
for i in range(5000):
bundle = MotorBundle(f"bundle{i}")
await bundle.connect(mock=True)
bundle.connect(mock=True)
duration = time.time() - start
assert duration < 1

Expand Down

0 comments on commit ff016ce

Please sign in to comment.