Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coro sleep timing #113

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/fastcs/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def __init__(
allowed_values: list[T] | None = None,
description: str | None = None,
) -> None:
assert (
datatype.dtype in ATTRIBUTE_TYPES
), f"Attr type must be one of {ATTRIBUTE_TYPES}, received type {datatype.dtype}"
assert datatype.dtype in ATTRIBUTE_TYPES, (
f"Attr type must be one of {ATTRIBUTE_TYPES}"
", received type {datatype.dtype}"
)
self._datatype: DataType[T] = datatype
self._access_mode: AttrMode = access_mode
self._group = group
Expand Down
12 changes: 8 additions & 4 deletions src/fastcs/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def _link_attribute_sender_class(single_mapping: SingleMapping) -> None:
for attr_name, attribute in single_mapping.attributes.items():
match attribute:
case AttrW(sender=Sender()):
assert (
not attribute.has_process_callback()
), f"Cannot assign both put method and Sender object to {attr_name}"
assert not attribute.has_process_callback(), (
f"Cannot assign both put method and Sender object to {attr_name}"
)

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


def _create_periodic_scan_coro(period, methods: list[Callable]) -> Callable:
async def _sleep():
await asyncio.sleep(period)

methods.append(_sleep) # Create periodic behavior

async def scan_coro() -> None:
while True:
await asyncio.gather(*[method() for method in methods])
await asyncio.sleep(period)

return scan_coro
6 changes: 3 additions & 3 deletions src/fastcs/transport/epics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def attr_is_enum(attribute: Attribute) -> bool:

"""
match attribute:
case Attribute(
datatype=String(), allowed_values=allowed_values
) if allowed_values is not None and len(allowed_values) <= MBB_MAX_CHOICES:
case Attribute(datatype=String(), allowed_values=allowed_values) if (
allowed_values is not None and len(allowed_values) <= MBB_MAX_CHOICES
):
return True
case _:
return False
Expand Down
2 changes: 1 addition & 1 deletion tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_over_defined_schema():

def test_version():
impl_version = "0.0.1"
expected = f"SingleArg: {impl_version}\n" f"FastCS: {__version__}\n"
expected = f"SingleArg: {impl_version}\nFastCS: {__version__}\n"
app = _launch(SingleArg, version=impl_version)
result = runner.invoke(app, ["version"])
assert result.exit_code == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/transport/epics/test_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def test_long_pv_names_discarded(mocker: MockerFixture):

assert long_name_controller.command_short_name.fastcs_method.enabled
long_command_name = (
"command_with_" "reallyreallyreallyreallyreallyreallyreally_long_name"
"command_with_reallyreallyreallyreallyreallyreallyreally_long_name"
)
assert not getattr(long_name_controller, long_command_name).fastcs_method.enabled

Expand Down
Loading