Uh oh!
There was an error while loading. Please reload this page.
Tweak transport closing - #1320
Conversation
florimondmanca
left a comment
There was a problem hiding this comment.
Exactly what I had in mind :)
Uh oh!
There was an error while loading. Please reload this page.
We probably want to cover the new transport closing behavior in the tests: classTestTransportClosing:
def__init__(self):
# Note that we're including 'proxies' here to *also* run through the# proxy context management, although we can't easily test that at the# moment, since we can't add proxies as transport instances.## Once we have a more generalised Mount API we'll be able to remove this# in favour of ensuring all mounts are context managed, which will# also necessarily include proxies.self.transport=Transport()
self.client=httpx.Client(transport=self.transport, proxies="http://www.example.com")
deftest_with_context_manager(self):
assertself.transport.events== []
withself.client:
passassertself.transport.events== [
"transport.__enter__",
"transport.close",
"transport.__exit__",
]
deftest_without_context_manager(self):
assertself.transport.events== []
self.client.close()
assertself.transport.events== [
"transport.close"
] |
johtso
commented
Sep 24, 2020
Also, we now get a lot of unclosed client UserWarnings when running the tests. |
lovelydinosaur
commented
Sep 24, 2020
Okay, right, which kinda gets to the heart of the two different options here. We can either:
We're in a slightly different position with |
lovelydinosaur
commented
Sep 24, 2020
So, I've made a slight tweak here, for AsyncClient only...
(We don't care about this for Not sure what we think about this. Incidentally wrt. CacheControl if you're expecting to expand it into sync+async support then you will want to only initialise the resources either on |
Was thinking exactly along these lines, makes sense to me.
Ah yes, look forward to exploring the a/sync rabbit hole! |
florimondmanca
commented
Sep 29, 2020
@tomchristie Heads up — we've got an interesting real-world case that we could test this new logic against in #1332. |
lovelydinosaur
commented
Oct 7, 2020
Superseeded by #1346 |
Closes #1317
client.close()is called, even if no requests have been made.