Skip to content

Commit

Permalink
fix: MightstoneHttpClient will not reuse client anymore
Browse files Browse the repository at this point in the history
this is due to big issue while trying to run consecutive call over different asyncio loops, this is a nightmare so F that and move as suggested in this HTTPX issue: encode/httpx#2473
  • Loading branch information
Guibod committed Mar 6, 2023
1 parent 0d899b0 commit 05d3336
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/mightstone/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ class MightstoneHttpClient:
"""

def __init__(self, transport: BaseTransport = None):
self.transport = transport
self.ijson = ijson

@property
def client(self):
# See: https://github.com/encode/httpx/issues/2473
options = {
"transport": transport,
"headers": {"cache-control": f"max-age={60*60*24}"},
"transport": self.transport,
"headers": {"cache-control": f"max-age={60 * 60 * 24}"},
}
if self.base_url:
options["base_url"] = self.base_url
self.client = AsyncClient(**options)
self.ijson = ijson

return AsyncClient(**options)

async def close(self):
await self.client.aclose()
Expand Down

0 comments on commit 05d3336

Please sign in to comment.