Skip to content

Commit

Permalink
Restore ExperimentAxisQuery.close, minimally
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Dec 20, 2024
1 parent dcbdba2 commit d47adcf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apis/python/src/tiledbsoma/_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,28 @@ def __init__(
)
self._index_factory = index_factory

def close(self) -> None:
pass

# WIP
# To be restored from somacore 1.0.17:
#
# def close(self) -> None:
# """Releases resources associated with this query.
#
# This method must be idempotent.
#
# Lifecycle: maturing
# """
# # Because this may be called during ``__del__`` when we might be getting
# # disassembled, sometimes ``_threadpool_`` is simply missing.
# # Only try to shut it down if it still exists.
# pool = getattr(self, "_threadpool_", None)
# if pool is None:
# return
# pool.shutdown()
# self._threadpool_ = None

def obs(
self,
*,
Expand Down
30 changes: 30 additions & 0 deletions apis/python/tests/test_experiment_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,36 @@ def test_error_corners(soma_experiment: Experiment):
next(query.varp(lyr_name))


@pytest.mark.parametrize("n_obs,n_vars", [(1001, 99)])
def test_query_cleanup(soma_experiment: soma.Experiment):
"""
Verify soma.Experiment.query works as context manager and stand-alone,
and that it cleans up correctly.
"""
from contextlib import closing

# Forces a context without a thread pool, which in turn causes ExperimentAxisQuery
# to own (and release) its own thread pool.
context = SOMATileDBContext()
context.threadpool = None
soma_experiment = get_soma_experiment_with_context(soma_experiment, context)

with soma_experiment.axis_query("RNA") as query:
assert query.n_obs == 1001
assert query.n_vars == 99
# WIP assert query.to_anndata("raw") is not None
# WIP assert query._threadpool_ is not None

# WIP assert query._threadpool_ is None

with closing(soma_experiment.axis_query("RNA")) as query:
pass
# WIP assert query.to_anndata("raw") is not None
# WIP assert query._threadpool_ is not None

# WIP assert query._threadpool_ is None


@pytest.mark.parametrize(
"n_obs,n_vars,obsp_layer_names,varp_layer_names,obsm_layer_names,varm_layer_names",
[(1001, 99, ["foo"], ["bar"], ["baz"], ["quux"])],
Expand Down

0 comments on commit d47adcf

Please sign in to comment.