Skip to content

Commit

Permalink
Adding method to tell if db is stopped.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Sep 23, 2016
1 parent cec6931 commit a6d77c2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions playhouse/sqliteq.py
Expand Up @@ -134,6 +134,8 @@ def __init__(self, database, use_gevent=False, autostart=False, readers=1,
self._autostart = autostart
self._results_timeout = results_timeout
self._num_readers = readers

self._is_stopped = True
self._thread_helper = self.get_thread_impl(use_gevent)(queue_max_size)
self._create_queues_and_workers()
if self._autostart:
Expand Down Expand Up @@ -201,15 +203,20 @@ def execute_sql(self, sql, params=None, require_commit=True, timeout=None):

def start(self):
with self._conn_lock:
if not self._is_stopped:
return False
self._writer.start()
for reader in self._readers:
reader.start()
logger.info('workers started.')
self._is_stopped = False
return True

def stop(self):
logger.debug('environment stop requested.')
with self._conn_lock:
if self._is_stopped:
return False
self._write_queue.put(StopIteration)
for _ in self._readers:
self._read_queue.put(StopIteration)
Expand All @@ -218,6 +225,10 @@ def stop(self):
reader.join()
return True

def is_stopped(self):
with self._conn_lock:
return self._is_stopped


class ThreadHelper(object):
__slots__ = ('queue_max_size',)
Expand Down

0 comments on commit a6d77c2

Please sign in to comment.