From 8f51c01ffa7cab3e6e8d3294c445c0cfb84080a2 Mon Sep 17 00:00:00 2001 From: Ouail Bendidi Date: Thu, 14 Sep 2023 01:39:26 +0200 Subject: [PATCH] fix not working with python3.7 --- httpx_cache/cache/file.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/httpx_cache/cache/file.py b/httpx_cache/cache/file.py index 9e9c197..765170a 100644 --- a/httpx_cache/cache/file.py +++ b/httpx_cache/cache/file.py @@ -1,5 +1,6 @@ import typing as tp from pathlib import Path +from functools import partial from anyio import to_thread from fasteners import ReaderWriterLock as RWLock @@ -102,7 +103,11 @@ async def aset( async with self.async_lock.writer: to_cache = self.serializer.dumps(response=response, content=content) try: - await to_thread.run_sync(filepath.write_bytes, to_cache) + await to_thread.run_sync( + filepath.write_bytes, + to_cache, + cancellable=True, + ) except Exception: return None @@ -115,4 +120,5 @@ def delete(self, request: httpx.Request) -> None: async def adelete(self, request: httpx.Request) -> None: filepath = get_cache_filepath(self.cache_dir, request, extra=self._extra) async with self.async_lock.writer: - await to_thread.run_sync(filepath.unlink, True) + _func = partial(filepath.unlink, missing_ok=True) + await to_thread.run_sync(_func, cancellable=True)