Skip to content

add notify_closing #896

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

Merged
merged 23 commits into from
Apr 13, 2025
Merged

add notify_closing #896

merged 23 commits into from
Apr 13, 2025

Conversation

graingert
Copy link
Collaborator

@graingert graingert commented Mar 17, 2025

Changes

  • add anyio.notify_closing
  • adjust wait_readable/wait_writable to checkpoint after registration and before waiting on the event.

anyio-zmq needs this feature to handle ZmqSocket.close calls

we expose the trio implemenation which is simple enough, and emulate the feature on asyncio. If someone is using add_reader themselves on an FD then you can't use it with anyio wait_readable/wait_writiable/notify_closing

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) added which would fail without your patch
  • You've updated the documentation (in docs/, in case of behavior changes or new
    features)
  • You've added a new changelog entry (in docs/versionhistory.rst).

If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.

Updating the changelog

If there are no entries after the last release, use **UNRELEASED** as the version.
If, say, your patch fixes issue #123, the entry should look like this:

- Fix big bad boo-boo in task groups
  (`#123 <https://github.com/agronholm/anyio/issues/123>`_; PR by @yourgithubaccount)

If there's no issue linked, just link to your pull request instead by updating the
changelog after you've created the PR.

store the closed attribute of waiting sockets separately from selector registration
this is because the selector registration status bool is not returned
from uvloop remove_reader or remove_writer, and the Selector thread
always removes registration before waking the calling event loop
@graingert graingert marked this pull request as ready for review March 18, 2025 14:27
@graingert graingert requested a review from agronholm March 18, 2025 14:33
graingert and others added 4 commits March 18, 2025 16:58
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
@graingert graingert requested a review from agronholm March 19, 2025 09:21
@agronholm agronholm added this to the 4.10 milestone Mar 24, 2025
@agronholm
Copy link
Owner

So, two questions came to mind:

  1. Is there a reason we're not just popping the fd from the dict when we have a result?
  2. Is there a reason why you're not simply setting the ClosedResourceError as the future's exception?

@graingert
Copy link
Collaborator Author

So, two questions came to mind:

1. Is there a reason we're not just popping the fd from the dict when we have a result?

that seems nicer, and allows new readers/writers slightly sooner. I've pushed that - it's a bit more complex though

2. Is there a reason why you're not simply setting the `ClosedResourceError` as the future's exception?

using a future for handling exceptions results in a reference cycle attached to a traceback and I'd like to avoid this. Also the traceback is harder to debug

@agronholm agronholm merged commit 820d3cc into master Apr 13, 2025
11 of 16 checks passed
@agronholm agronholm deleted the notify-closing branch April 13, 2025 23:44
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

Successfully merging this pull request may close these issues.

2 participants