Skip to content

Commit 144f4ea

Browse files
holyMolyTolliKirstinjoein
authored
Fix/lazy load local mode (#1134)
* Fix: Lazy load QdrantLocal to support read-only envs * Fix: Lazy load QdrantLocal to support read-only envs * Fix: Regenerate async client using Python 3.10 to match CI * chore: add comments to portalocker import --------- Co-authored-by: Kirstin <[email protected]> Co-authored-by: George Panchuk <[email protected]>
1 parent c701285 commit 144f4ea

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

qdrant_client/local/async_qdrant_local.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from typing import Any, Generator, Iterable, Mapping, Sequence, get_args
2121
from uuid import uuid4
2222
import numpy as np
23-
import portalocker
2423
from qdrant_client.common.client_warnings import show_warning, show_warning_once
2524
from qdrant_client._pydantic_compat import to_dict
2625
from qdrant_client.async_client_base import AsyncQdrantBase
@@ -83,6 +82,8 @@ async def close(self, **kwargs: Any) -> None:
8382
)
8483
try:
8584
if self._flock_file is not None and (not self._flock_file.closed):
85+
import portalocker
86+
8687
portalocker.unlock(self._flock_file)
8788
self._flock_file.close()
8889
except TypeError:
@@ -124,6 +125,8 @@ def _load(self) -> None:
124125
with open(lock_file_path, "w") as f:
125126
f.write("tmp lock file")
126127
self._flock_file = open(lock_file_path, "r+")
128+
import portalocker
129+
127130
try:
128131
portalocker.lock(
129132
self._flock_file,

qdrant_client/local/qdrant_local.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from uuid import uuid4
1818

1919
import numpy as np
20-
import portalocker
2120

2221
from qdrant_client.common.client_warnings import show_warning, show_warning_once
2322
from qdrant_client._pydantic_compat import to_dict
@@ -83,6 +82,9 @@ def close(self, **kwargs: Any) -> None:
8382

8483
try:
8584
if self._flock_file is not None and not self._flock_file.closed:
85+
import portalocker # `portalocker` can't be imported at the top level: it checks for writeable
86+
# directories on import and crashes in read-only systems even if local mode is not used
87+
8688
portalocker.unlock(self._flock_file)
8789
self._flock_file.close()
8890
except TypeError: # sometimes portalocker module can be garbage collected before
@@ -134,6 +136,10 @@ def _load(self) -> None:
134136
with open(lock_file_path, "w") as f:
135137
f.write("tmp lock file")
136138
self._flock_file = open(lock_file_path, "r+")
139+
140+
import portalocker # `portalocker` can't be imported at the top level: it checks for writeable directories
141+
# on import and crashes in read-only systems even if local mode is not used
142+
137143
try:
138144
portalocker.lock(
139145
self._flock_file,

0 commit comments

Comments
 (0)