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

Expose ResourceGuard #627

Closed
1 task done
Fuyukai opened this issue Nov 4, 2023 · 3 comments · Fixed by #630
Closed
1 task done

Expose ResourceGuard #627

Fuyukai opened this issue Nov 4, 2023 · 3 comments · Fixed by #630
Labels
enhancement New feature or request

Comments

@Fuyukai
Copy link
Contributor

Fuyukai commented Nov 4, 2023

Things to check first

  • I have searched the existing issues and didn't find my feature already requested there

Feature description

ResourceGuard should be exposed publically, instead of requiring importing from an internal module.

Use case

It's a useful object for implementing streams that use pumping tasks behind the scenes.

@Fuyukai Fuyukai added the enhancement New feature or request label Nov 4, 2023
@agronholm
Copy link
Owner

I've considered this. It would help if you elaborated on the use case.

@gschaffner
Copy link
Collaborator

gschaffner commented Nov 4, 2023

i can't speak for others, but i implemented a ResourceGuard equivalent in a downstream library because i needed to ensure that users doing broken locking would raise instead of silently causing a framer & multiplexer to lose track of stream state and start (a) sending gibberish to the peer and/or (b) returning gibberish to the user1.

i also made the mistake of not exposing it publicly in that library, which led folks at work writing further-downstream code atop AnyIO+aforementioned middle lib to again reimplement a ResourceGuard equivalent a third time.

it's a tiny implementation to copy around everywhere, but i'd love to see it exposed in AnyIO.

Footnotes

  1. the library needed to use ResourceGuard, not Lock, because locking has to be done further downstream by application developers to avoid the bugs associated with using recursive locks for non-recursive tasks. for context, this is for controlling scientific instruments, where we need proper locking so that we don't have multiple clients interrupting each other's sequences of device commands/queries. these instruments are very stateful and it is annoying.

@Fuyukai
Copy link
Contributor Author

Fuyukai commented Nov 4, 2023

It would help if you elaborated on the use case.

My client class uses a background task to read messages from the socket and turn them into objects, then publishes them on a channel for the downstream users to read. It's essentially the same reason as socket streams having their receive/sends wrapped in a conflict detector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants