Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Restore ExperimentAxisQuery.close #3494

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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