Skip to content

Commit 7f69322

Browse files
author
Jinnapat Indrapiromkul
committed
Close sqlite connection after use
1 parent 8ea8686 commit 7f69322

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

plottr/data/qcodes_dataset.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import os
77
import sys
8+
from contextlib import closing
89
from itertools import chain
910
from operator import attrgetter
1011
from typing import Dict, List, Set, Union, TYPE_CHECKING, Any, Tuple, Optional, cast
@@ -191,22 +192,23 @@ def get_runs_from_db(path: str, start: int = 0,
191192
"""
192193
initialise_or_create_database_at(path)
193194
if sys.version_info >= (3, 11):
194-
conn = conn_from_dbpath_or_conn(read_only=True)
195+
conn = conn_from_dbpath_or_conn(conn=None, path_to_db=path, read_only=True)
195196
else:
196-
conn = conn_from_dbpath_or_conn()
197-
exps = experiments(conn=conn)
197+
conn = conn_from_dbpath_or_conn(conn=None, path_to_db=path)
198+
with closing(conn) as conn_:
199+
exps = experiments(conn=conn_)
198200

199-
datasets = sorted(
200-
chain.from_iterable(exp.data_sets() for exp in exps),
201-
key=attrgetter('run_id')
202-
)
201+
datasets = sorted(
202+
chain.from_iterable(exp.data_sets() for exp in exps),
203+
key=attrgetter('run_id')
204+
)
203205

204-
# There is no need for checking whether ``stop`` is ``None`` because if
205-
# it is the following is simply equivalent to ``datasets[start:]``
206-
datasets = datasets[start:stop]
206+
# There is no need for checking whether ``stop`` is ``None`` because if
207+
# it is the following is simply equivalent to ``datasets[start:]``
208+
datasets = datasets[start:stop]
207209

208-
overview = {ds.run_id: get_ds_info(ds, get_structure=get_structure)
209-
for ds in datasets}
210+
overview = {ds.run_id: get_ds_info(ds, get_structure=get_structure)
211+
for ds in datasets}
210212
return overview
211213

212214

0 commit comments

Comments
 (0)