feat: context managers in ServiceBrowser and AsyncServiceBrowser#1233
Conversation
|
Can you add a test for these? Also generally its not recommended to have short running instances if you can avoid it since it churns the network traffic quite a bit. There are obviously uses cases for it, and people do get it wrong a lot (and leak browsers) so I'm inclined to move this forward |
cb069ef to
048d856
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1233 +/- ##
==========================================
- Coverage 99.82% 99.78% -0.04%
==========================================
Files 25 25
Lines 2798 2809 +11
Branches 480 480
==========================================
+ Hits 2793 2803 +10
Misses 3 3
- Partials 2 3 +1
☔ View full report in Codecov by Sentry. |
I added tests now Though there seems to be a race condition between calling
My use case may be for that, my own project intends to just run the browser briefly at startup |
|
Async_cancel should not race Cancel should but you can do asyncio.sleep(0) to ensure the call soon is run |
|
I put the call to |
That makes more sense, I wasn't sure how to do that until you pointed out how, thanks |
I started using this package for the first time recently, and when trying to use the async browser example, I found the requirement to use
AsyncServiceBrowser.async_cancel()at the end of everything. After discovering that AsyncZeroconf has an async context manager, I found that AsyncServiceBrowser did not have its own.I tried my best to replicate #284 (#177), however I am not sure how to go about adding test coverage. Apologies for not adding any.
Here's an example of how my code is simplified using the context manager (in Python 3.11):