-
Notifications
You must be signed in to change notification settings - Fork 26
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 new timeout for observe_value #650
Conversation
Spoke too soon, doesn't work on CI... |
Ok, looks like there are actually numerous python bugs in I think this fixes your particular use case, but you can't pass a I would also suggest that you move the opencv calls to another thread and consume all the values from the Queue between the two, dropping old updates. |
Great, thank you! |
Ok, still some issues will this, will investigate next week |
observe_value runs in a lot of tests, so the testing checks for max_yields needs to be much more than the one for observe_value otherwise they fight each other
@DominicOram @olliesilvester @rtuck99 I think this is now working, but would be good to talk through the code with one of you to check I understand the problem correctly |
I'm about today, I'm just reading through the changes now |
Discussed with @coretl, I think this change fixes our issue but I will investigate further to see if there are any safer solutions |
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.
This looks reasonable to me, especially if @olliesilvester has talked over it too. My only comment would be that if we think it's mostly a problem with asyncio.wait_for
in <3.11 then we should add a comment/issue to drop it when we drop 3.11. But if we think there are other, more general, problems this might catch then maybe we shouldn't drop it.
I tried using I'm leaning towards just not using
instead, and warn against using |
It's messy, but it's probably the most pragmatic solution here, then we relegate @DominicOram thoughts? @olliesilvester when this is decided would you mind amending this PR or making a new one with the implementation please? |
I'm not a big fan of this, having to roll you're own timeout code when there's provision for it in |
Yeah, the timeout will be in |
I've given this a go but there are some extra things to think about
Solution here is either to either give
I think the clever decorator is best here, assuming it isn't too hard to make Thoughts @coretl? |
I suggest something like: async def observe_value(signal, timeout=None, overall_timeout=None):
overall_deadline = time.monotonic() + overall_timeout if overall_timeout else None
...
while True:
deadline = time.monotonic() + timeout if timeout else overall_deadline
if deadline and overall_deadline:
deadline = min(deadline, overall_deadline)
value = await asyncio.wait_for(q.get(), deadline - time.monotonic() if deadline else 0)
... |
Although people will probably still do |
@DominicOram @olliesilvester this is the epics test I mentioned in DiamondLightSource/dodal#897 (comment)
It looks like I need to yield after the
q.get
rather than before to let the timeout break without an extra yield