Skip to content

Commit e4d710b

Browse files
authored
Merge pull request #113 from DiamondLightSource/sleep_timing
Fix period of scan tasks
2 parents f67c15a + 0b10f50 commit e4d710b

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

src/fastcs/attributes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def __init__(
6969
allowed_values: list[T] | None = None,
7070
description: str | None = None,
7171
) -> None:
72-
assert (
73-
datatype.dtype in ATTRIBUTE_TYPES
74-
), f"Attr type must be one of {ATTRIBUTE_TYPES}, received type {datatype.dtype}"
72+
assert datatype.dtype in ATTRIBUTE_TYPES, (
73+
f"Attr type must be one of {ATTRIBUTE_TYPES}"
74+
", received type {datatype.dtype}"
75+
)
7576
self._datatype: DataType[T] = datatype
7677
self._access_mode: AttrMode = access_mode
7778
self._group = group

src/fastcs/backend.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ def _link_attribute_sender_class(single_mapping: SingleMapping) -> None:
8383
for attr_name, attribute in single_mapping.attributes.items():
8484
match attribute:
8585
case AttrW(sender=Sender()):
86-
assert (
87-
not attribute.has_process_callback()
88-
), f"Cannot assign both put method and Sender object to {attr_name}"
86+
assert not attribute.has_process_callback(), (
87+
f"Cannot assign both put method and Sender object to {attr_name}"
88+
)
8989

9090
callback = _create_sender_callback(attribute, single_mapping.controller)
9191
attribute.set_process_callback(callback)
@@ -154,9 +154,13 @@ def _get_periodic_scan_coros(scan_dict: dict[float, list[Callable]]) -> list[Cal
154154

155155

156156
def _create_periodic_scan_coro(period, methods: list[Callable]) -> Callable:
157+
async def _sleep():
158+
await asyncio.sleep(period)
159+
160+
methods.append(_sleep) # Create periodic behavior
161+
157162
async def scan_coro() -> None:
158163
while True:
159164
await asyncio.gather(*[method() for method in methods])
160-
await asyncio.sleep(period)
161165

162166
return scan_coro

src/fastcs/transport/epics/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def attr_is_enum(attribute: Attribute) -> bool:
3636
3737
"""
3838
match attribute:
39-
case Attribute(
40-
datatype=String(), allowed_values=allowed_values
41-
) if allowed_values is not None and len(allowed_values) <= MBB_MAX_CHOICES:
39+
case Attribute(datatype=String(), allowed_values=allowed_values) if (
40+
allowed_values is not None and len(allowed_values) <= MBB_MAX_CHOICES
41+
):
4242
return True
4343
case _:
4444
return False

tests/test_launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_over_defined_schema():
102102

103103
def test_version():
104104
impl_version = "0.0.1"
105-
expected = f"SingleArg: {impl_version}\n" f"FastCS: {__version__}\n"
105+
expected = f"SingleArg: {impl_version}\nFastCS: {__version__}\n"
106106
app = _launch(SingleArg, version=impl_version)
107107
result = runner.invoke(app, ["version"])
108108
assert result.exit_code == 0

tests/transport/epics/test_ioc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def test_long_pv_names_discarded(mocker: MockerFixture):
436436

437437
assert long_name_controller.command_short_name.fastcs_method.enabled
438438
long_command_name = (
439-
"command_with_" "reallyreallyreallyreallyreallyreallyreally_long_name"
439+
"command_with_reallyreallyreallyreallyreallyreallyreally_long_name"
440440
)
441441
assert not getattr(long_name_controller, long_command_name).fastcs_method.enabled
442442

0 commit comments

Comments
 (0)