-
Notifications
You must be signed in to change notification settings - Fork 87
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
Add async capabilities to protocols #1502
Conversation
@callumforrester any comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have left a few, @tacaswell and @danielballan feel free to correct me on any of them
@thomascobb Food for thought: Have we considered maintaining two sets of protocols rather than one set with doubled-up capabilities? For example: @runtime_checkable
class Movable(Protocol):
def set(self, value: Any) -> Status:
"""Return a ``Status`` that is marked done when the device is done moving."""
...
@runtime_checkable
class AsyncMovable(Protocol):
async def set(self, value: Any) -> AsyncStatus:
"""Return ``AsyncStatus`` that is marked done when the device is done moving."""
... It allows for a clean break and doesn't change where the differentiating logic in the RE has to go. I can imagine there are disadvantages though, bloat for one. It might help to resolve some of the backwards-compatibility issues discussed here though. |
I started there, but it turns out runtime_checkable can't tell the difference between those two protocols, which means an additional |
@thomascobb really basic question here---sorry I'm slow 😄 The protocols already support callbacks for subscription. Why do we need to change the protocols for ophyd v2? Couldn't asyncio be an implementation detail? |
This is driven by 2 things:
If we narrowed the protocol be: Callback = Callable[[Dict[str, EventData]], SyncOrAsync[None]]
@runtime_checkable
class Subscribable(Protocol):
def subscribe(self, function: Callback) -> None:
...
def clear_sub(self, function: Callback) -> None:
... Then:
|
Thanks @thomascobb
Wow, I missed this subtlety I see what you mean that needs to change.
As in passing awaitable callbacks into my subscribe method? Can you say way? You can write a synchronous function which launches coroutine(s), isn't that enough? |
That's a good point, I was thinking about this like I'll make some edits to the PR and resolve some of these threads... |
A suggested name for this file: |
I don't think
@danielballan, @tacaswell, @untzag, @ksunden what do you reckon? |
Remaining
|
I have a fairly strong preference to follow the Python language standards where possible. Python chose the word "Protocol", I think we should be consistent. |
I think we should escalate the concept of components to protocol in a future PR. |
At the moment I don't have the |
I think nested hardware interfaces are common to many different control systems. Queueserver recently added support for dot syntax to address components. As more control systems become supported it would be useful to standardize this syntax because right now it's just a convention based on how ophyd did it (as far as I know). |
|
|
I think we should try and close this out sooner rather than later, so have raised #1517 to cover issues that don't have an immediately obvious solution, or need more discussion. They should all be additions rather than changes to this PR, so this is probably a good section to merge on its own. |
rewindable (which is currently implemented as a It is a mechanism that a device can use to inform trigger and read that going back and naively re-triggering the device when recovering from an interruption (either due to manual intervention by the user or from suspenders). The work also needs to be done for I think that changing this to be a normal attribute is on the table. Trying to re-construct what we were thinking I suspect we made it a signal so that we could put the value in |
is_movable now checks the object supports both protocols.Movable and protocols.Readable
I have squashed this and rebased on master in #1522 |
Description
An attempt at the tweaks outlined in #1501 to provoke discussion
Motivation and Context
So that asyncio can be used in
ophyd.v2
and in preparation for bluesky/ophyd#1013How Has This Been Tested?
Not tested yet, will be tested as part of
ophyd.v2
when changes are agreed, but here as a draft for discussion