Skip to content

Commit

Permalink
Allow tiledb_config to acquire lock in native_context
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Feb 23, 2024
1 parent 2421648 commit 638c7f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apis/python/src/tiledbsoma/_tdb_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def open(
soma_object = clib.SOMAObject.open(
uri, open_mode, context.native_context, (0, timestamp_ms)
)

# Avoid creating a TileDB-Py Ctx unless necessary
obj_type = (
soma_object.type
if soma_object is not None
else tiledb.object_type(uri, ctx=context.tiledb_ctx)
)

if not obj_type:
raise DoesNotExistError(f"{uri!r} does not exist")

Expand All @@ -80,7 +80,7 @@ def open(
"array",
):
return ArrayWrapper.open(uri, mode, context, timestamp)

if obj_type in (
"SOMACollection",
"SOMAExperiment",
Expand Down
14 changes: 9 additions & 5 deletions apis/python/src/tiledbsoma/options/_soma_tiledb_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(
self._timestamp_ms = _maybe_timestamp_ms(timestamp)

"""Lazily construct clib.SOMAContext."""
self._native_context = None
self._native_context: Optional[clib.SOMAContext] = None

@property
def timestamp_ms(self) -> Optional[int]:
Expand All @@ -155,10 +155,14 @@ def timestamp(self) -> Optional[datetime.datetime]:
def native_context(self) -> clib.SOMAContext:
"""The C++ SOMAContext for this SOMA context."""
with self._lock:
if self._native_context is None:
self._native_context = clib.SOMAContext(
{k: str(self.tiledb_config[k]) for k in self.tiledb_config}
)
if self._native_context is not None:
return self._native_context

# tiledb_config also acquires the lock so we must first release it and
# then reacquire it
cfg = self.tiledb_config
with self._lock:
self._native_context = clib.SOMAContext({k: str(cfg[k]) for k in cfg})
return self._native_context

@property
Expand Down

0 comments on commit 638c7f5

Please sign in to comment.