-
Notifications
You must be signed in to change notification settings - Fork 70
Add explicit close method #166
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #166 +/- ##
==========================================
+ Coverage 93.85% 96.76% +2.91%
==========================================
Files 3 3
Lines 374 557 +183
Branches 29 36 +7
==========================================
+ Hits 351 539 +188
+ Misses 14 10 -4
+ Partials 9 8 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces explicit resource cleanup to DNSResolver
by adding a close()
method, async context manager support, and an improved __del__
for automatic cleanup. It also updates tests to cover the new functionality, bumps the minimum pycares
dependency, and updates the documentation.
- Add
_cleanup()
,async close()
,__aenter__
/__aexit__
, and enhanced__del__
inDNSResolver
- Extend test suite with close, idempotence, destructor, and context‐manager tests
- Bump
pycares
requirement to>=4.9.0
and document the new API
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/test_aiodns.py | New tests for close() , context manager, and __del__ cleanup; updated tearDown to call close() |
setup.py | Updated pycares minimum version in install_requires |
aiodns/init.py | Implemented _cleanup() , close() , async context manager, and refined destructor behavior |
README.rst | Documented close() method and async context manager usage |
Comments suppressed due to low confidence (2)
setup.py:24
- Bumping the minimum
pycares
version to 4.9.0 may affect users upgrading from older versions. Ensure this change is documented in the changelog and migration notes.
install_requires=['pycares>=4.9.0'],
aiodns/init.py:369
- [nitpick] In
__del__
, calling_cleanup()
may raise if the loop or channel state is invalid. Wrap the call intry/except
to suppress exceptions during garbage collection.
def __del__(self) -> None:
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Thanks. I'll see if I can do a release before lunch |
What do these changes do?
This PR adds a
close()
method to theDNSResolver
class to allow for explicit cleanup of resources. The implementation includes:close()
method that cleanly shuts down the resolver by canceling timers, removing file descriptors, and closing the pycares channel__aenter__
and__aexit__
) for automatic cleanup when usingasync with
__del__
method that automatically calls cleanup when the resolver is garbage collectedAre there changes in behavior for the user?
await resolver.close()
async with aiodns.DNSResolver() as resolver:
Related issue number
Fixes #165
Checklist