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

wait_task_rescheduled API revision umbrella issue #1253

Open
oremanj opened this issue Oct 17, 2019 · 0 comments
Open

wait_task_rescheduled API revision umbrella issue #1253

oremanj opened this issue Oct 17, 2019 · 0 comments

Comments

@oremanj
Copy link
Member

oremanj commented Oct 17, 2019

From discussion in chat here: https://gitter.im/python-trio/general?at=5da7d898894dee56e558319b

If we want to make wait_task_rescheduled() better, what would we want to change?

  • It has a complicated calling convention with the raise_cancel callback parameter. We might be able to get rid of this now that Cancelled exceptions are stateless, provided that we also modify KeyboardInterrupt handling to inject a new task rather than waking up an existing task (as discussed at Proposal: make checkpoint_if_cancelled() sync-colored and rename it accordingly #961 (comment))
  • It has a very particular contract and isn't much able to diagnose violations thereof (such as calling reschedule() twice, or returning Abort.SUCCEEDED and then calling reschedule())
  • The fact that it's flexible enough for unusual cases (asynchronous cancellation, etc) makes it a bit daunting to use in simple cases.

One promising-seeming idea is to reify a "wake token" (strawman name) which must be used to wake the task (rather than passing the task object itself to trio.hazmat.reschedule()). Then the wake token could capture additional state like "did this wakeup occur yet?", and we could also move custom_sleep_data from Task to WakeToken for better scoping.

The initial impetus for the "wake token" idea involved forced wakeups when we notice a missing await (see #79, and specifically the version in bpo-30491), but we might sidestep that need by injecting an exception in the parent nursery instead, in order to have fewer special cases. Wake tokens would still be useful for making the API more forgiving if it's misused.

Other thoughts:

@oremanj oremanj changed the title Potential revisions to wait_task_rescheduled API wait_task_rescheduled API revision umbrella issue Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant