Skip to content

Commit

Permalink
Allow double close in sqlite backend (#3148)
Browse files Browse the repository at this point in the history
  • Loading branch information
aseyboldt authored and ColCarroll committed Aug 12, 2018
1 parent 8a55b69 commit 7de797f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pymc3/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ def setup(self, draws, chain):
self._create_table()
self._is_setup = True
self._create_insert_queries()
self._closed = False

def _create_table(self):
template = TEMPLATES['table']
with self.db.con:
for varname, var_cols in self._var_cols.items():
if np.issubdtype(self.var_dtypes[varname], np.int):
if np.issubdtype(self.var_dtypes[varname], np.integer):
dtype = 'INT'
else:
dtype = 'FLOAT'
Expand Down Expand Up @@ -164,8 +165,11 @@ def _execute_queue(self):
self._queue[varname] = []

def close(self):
if self._closed:
return
self._execute_queue()
self.db.close()
self._closed = True

# Selection methods

Expand Down
4 changes: 4 additions & 0 deletions pymc3/tests/backend_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def test_append(self):
self.strace.setup(self.draws, self.chain, self.sampler_vars)
assert len(self.strace) == 0

def test_double_close(self):
self.strace.close()
self.strace.close()

def teardown_method(self):
if self.name is not None:
remove_file_or_directory(self.name)
Expand Down

0 comments on commit 7de797f

Please sign in to comment.