[FEA]: Add context managers to objects where resource cleanup is required
Nobody has claimed this yet.
- Dominant language
- Cython
- Stars
- 3.4k
- Forks
- 329
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 116
Description
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this request and that I agree to the Code of Conduct
Area
cuda.core
Is your feature request related to a problem? Please describe.
#1711 illustrates a number of places where users are required to perform explicit cleanup of objects, by updating the examples to use try/finally and performing cleanup within the finally.
#1586 is related and probably a part of this work, but not as broad as this.
Describe the solution you'd like
We should implement context managers on any objects that need an explicit close or other resource revocation.
This includes at least Graph, GraphBuilder, Stream, possibly others.
Once these context managers are added, we should update any examples/docs/tests to use them.
Describe alternatives you've considered
I have read of resistance to this idea elsewhere based on the performance issues with contextlib.contextmanager, and if we provide them, users will use them over manual resource deallocation and pay the performance penalty everywhere.
However, context managers as a general concept (implemented with __enter__ and __exit__) do not have a major performance problem relative to correctly written code with a try/finally, as far as I know. I'm happy to be corrected on that, if there is in fact a performance problem vs. /correct/ code.
I think supporting context managers would be a major ergonomic improvement over manual tracking of context or even try/finally (which doesn't compose as well as with).
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the cuda.core objects named in the request: Graph, GraphBuilder, and Stream, along with the cleanup examples from #1711. Identify which objects require explicit close or resource revocation, then update the relevant examples, documentation, and tests to use context managers and verify cleanup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- hpc
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100