Skip to content
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
4 changes: 2 additions & 2 deletions src/fastcs/attributes/attr_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ async def update_attribute():
try:
self.log_event("Update attribute", topic=self)
await update_callback(self)
except Exception as e:
logger.opt(exception=e).error("Update loop failed", attribute=self)
except Exception:
logger.error("Attribute update loop stopped", attribute=self)
raise

return update_attribute
2 changes: 2 additions & 0 deletions src/fastcs/attributes/attr_w.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ async def put(self, setpoint: DType_T, sync_setpoint: bool = False) -> None:
"Sync setpoint failed", attribute=self, setpoint=setpoint
)

self.log_event("Put complete", setpoint=setpoint, attribute=self)

async def _call_sync_setpoint_callbacks(self, setpoint: DType_T) -> None:
if self._sync_setpoint_callbacks:
await asyncio.gather(
Expand Down
8 changes: 2 additions & 6 deletions src/fastcs/control_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from IPython.terminal.embed import InteractiveShellEmbed

from fastcs.controllers import BaseController, Controller
from fastcs.exceptions import FastCSError
from fastcs.logging import bind_logger
from fastcs.methods import Command, Scan, ScanCallback
from fastcs.tracer import Tracer
Expand Down Expand Up @@ -63,11 +62,8 @@ async def _start_scan_tasks(self):
def _scan_done(self, task: asyncio.Task):
try:
task.result()
except Exception as e:
raise FastCSError(
"Exception raised in scan method of "
f"{self._controller.__class__.__name__}"
) from e
except Exception:
logger.exception("Exception raised in scan task")

def _stop_scan_tasks(self):
for task in self._scan_tasks:
Expand Down
14 changes: 14 additions & 0 deletions src/fastcs/methods/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
from types import MethodType

from fastcs.controllers import BaseController
from fastcs.logging import bind_logger
from fastcs.methods.method import Controller_T, Method

logger = bind_logger(logger_name=__name__)

UnboundScanCallback = Callable[[Controller_T], Coroutine[None, None, None]]
"""A Scan callback that is unbound and must be called with a `Controller` instance"""
ScanCallback = Callable[[], Coroutine[None, None, None]]
Expand Down Expand Up @@ -36,6 +39,17 @@ def _validate(self, fn: ScanCallback) -> None:
async def __call__(self):
return await self._fn()

@property
def fn(self):
async def scan():
try:
return await self._fn()
except Exception:
logger.error("Scan update loop stopped", fn=self._fn)
raise

return scan


class UnboundScan(Method[Controller_T]):
"""A wrapper of an unbound `Controller` method to be bound into a `Scan`.
Expand Down
3 changes: 0 additions & 3 deletions tests/test_control_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from fastcs.control_system import FastCS, build_controller_api
from fastcs.controllers import Controller
from fastcs.datatypes import Int
from fastcs.exceptions import FastCSError
from fastcs.methods import Command, command, scan
from fastcs.util import ONCE

Expand Down Expand Up @@ -152,8 +151,6 @@ async def raise_exception(self):
task = asyncio.create_task(fastcs.serve(interactive=False))
# This allows scan time to run
await asyncio.sleep(0.2)
# _scan_done should raise an exception
assert isinstance(exception_info["exception"], FastCSError)
for task in fastcs._scan_tasks:
internal_exception = task.exception()
assert internal_exception
Expand Down