ontology-access-kit
ontology-access-kit copied to clipboard
Unclosed sqlite connection during garbage collection raises warning
With this simple schema example_dynamic_term_set.yaml:
id: https://w3id.org/linkml/examples/nwb_dynamic_enums
name: nwb_dynamic_enums
prefixes:
CL: http://purl.obolibrary.org/obo/CL_
enums:
NeuronTypeEnum:
reachable_from:
source_ontology: obo:cl
source_nodes:
- CL:0000540 ## neuron
include_self: false
relationship_types:
- rdfs:subClassOf
and this simple code test_value_set_expander.py:
from oaklib.utilities.subsets.value_set_expander import ValueSetExpander
expander = ValueSetExpander()
schema_path = "example_dynamic_term_set.yaml"
expander.expand_in_place(schema_path, ["NeuronTypeEnum"], "test.yaml")
Running with python -W error -W ignore::DeprecationWarning -W ignore:pkg_resources:UserWarning test_value_set_expander.py results in
Exception ignored in: <sqlite3.Connection object at 0x12ff5b100>
ResourceWarning: unclosed database in <sqlite3.Connection object at 0x12ff5b100>
I traced this to the sql connector and engine Engine(sqlite:////Users/rly/.data/oaklib/cl.db) not being properly closed when python execution ends and garbage collection happens. This seems to be resolved by adding:
def __del__(self):
if self._session is not None:
self._session.close()
if self.engine is not None:
self.engine.dispose()
to sql_implementation.py.