diff --git a/apis/python/src/tiledbsoma/_query.py b/apis/python/src/tiledbsoma/_query.py index 4071788e78..55b2c512b4 100644 --- a/apis/python/src/tiledbsoma/_query.py +++ b/apis/python/src/tiledbsoma/_query.py @@ -243,7 +243,6 @@ def __init__( index_factory=index_factory, ) self._index_factory = index_factory - self._threadpool_: Optional[ThreadPoolExecutor] = None def obs( self, @@ -477,20 +476,7 @@ def to_anndata( # Context management 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 + pass def __enter__(self) -> Self: return self @@ -775,13 +761,7 @@ def _threadpool(self) -> ThreadPoolExecutor: """ Returns the threadpool provided by the experiment's context. If not available, creates a thread pool just in time.""" - context = self.experiment.context - if context and context.threadpool: - return context.threadpool - - if self._threadpool_ is None: - self._threadpool_ = ThreadPoolExecutor() - return self._threadpool_ + return self.experiment.context.threadpool @attrs.define(frozen=True) diff --git a/apis/python/tests/test_experiment_query.py b/apis/python/tests/test_experiment_query.py index 401831f29d..f0e27d2237 100644 --- a/apis/python/tests/test_experiment_query.py +++ b/apis/python/tests/test_experiment_query.py @@ -540,35 +540,6 @@ 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: Experiment): - """ - Verify 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 - assert query.to_anndata("raw") is not None - assert query._threadpool_ is not None - - assert query._threadpool_ is None - - with closing(soma_experiment.axis_query("RNA")) as query: - assert query.to_anndata("raw") is not None - assert query._threadpool_ is not None - - 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"])],