Skip to content

Commit 4819b50

Browse files
Parallel handle lockbusy (#855)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 7ce600b commit 4819b50

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

paperqa/agents/search.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,21 @@ async def remove_from_index(self, file_location: str) -> None:
364364

365365
self.changed = True
366366

367+
@retry(
368+
stop=stop_after_attempt(1000),
369+
wait=wait_random_exponential(multiplier=0.25, max=60),
370+
retry=retry_if_exception_type(AsyncRetryError),
371+
reraise=True,
372+
)
367373
async def save_index(self) -> None:
368-
async with self.writer(reset=True) as writer:
369-
writer.commit()
370-
writer.wait_merging_threads()
374+
try:
375+
async with self.writer(reset=True) as writer:
376+
writer.commit()
377+
writer.wait_merging_threads()
378+
except ValueError as e:
379+
if "Failed to acquire Lockfile: LockBusy." in str(e):
380+
raise AsyncRetryError("Failed to acquire lock") from e
381+
raise
371382
file_index_path = await self.file_index_filename
372383
async with await anyio.open_file(file_index_path, "wb") as f:
373384
await f.write(zlib.compress(pickle.dumps(await self.index_files)))

0 commit comments

Comments
 (0)