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

Add a .timeout attribute to CancelScope? #861

Closed
njsmith opened this issue Jan 17, 2019 · 3 comments
Closed

Add a .timeout attribute to CancelScope? #861

njsmith opened this issue Jan 17, 2019 · 3 comments

Comments

@njsmith
Copy link
Member

njsmith commented Jan 17, 2019

Now that CancelScopes are becoming more exposed to users with #607 / #835, it occurred to me that it might be nice to have a weird magical .timeout property on them. The definition would be:

@property
def timeout(self):
    return max(0.0, self._deadline - trio.current_time())

@timeout.setter
def timeout(self, new_timeout):
    self.deadline = trio.current_time() + new_timeout
@njsmith
Copy link
Member Author

njsmith commented Jan 17, 2019

...Of course as soon as I posted that I realized there's a probably-fatal flaw. This code looks all nice and sensible:

cancel_scope.timeout += 1

But with the definition above, it would call current_time() twice, so it would actually cause the deadline to increase by slightly more than 1 second, which seems like a super obscure gotcha.

@smurfix
Copy link
Contributor

smurfix commented Jan 18, 2019

Well, we could always create .timeout as a magical int-derived object that actually supports iadd by updating its parent … though that would have interesting overhead (and require a weakref). Let's just add a .timeout_after method (or whatever the name shall be) instead.

@njsmith
Copy link
Member Author

njsmith commented Jan 27, 2019

I'm not convinced there's anything better to do here than what we're already doing. We can always re-open later when we have more experience with the new CancelScope APIs.

@njsmith njsmith closed this as completed Jan 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants