Skip to content

Commit

Permalink
Fix in-memory queue using shared-cache
Browse files Browse the repository at this point in the history
When share in-memory queue in multi-thread, the queue is not
properly synced between threads, this commit uses shared-cache
to achive the synchronization.
fixes #31
  • Loading branch information
peter-wangxu committed Nov 1, 2017
1 parent 71ded7c commit a018857
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions persistqueue/sqlbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ def _init(self):
self._conn.commit()
# Setup another session only for disk-based queue.
if self.multithreading:
if not self.memory_sql:
self._putter = self._new_db_connection(
self.path, self.multithreading, self.timeout)
self._putter = self._new_db_connection(
self.path, self.multithreading, self.timeout)
if self.auto_commit is False:
log.warning('auto_commit=False is still experimental,'
'only use it with care.')
Expand All @@ -110,10 +109,10 @@ def _init(self):
self.put_event = threading.Event()

def _new_db_connection(self, path, multithreading, timeout):
conn = None
if path == self._MEMORY:
conn = sqlite3.connect(path,
check_same_thread=not multithreading)
conn = sqlite3.connect(database='file::memory:?cache=shared&model=memory',
check_same_thread=not multithreading,
uri=True)
else:
conn = sqlite3.connect('{}/data.db'.format(path),
timeout=timeout,
Expand Down

0 comments on commit a018857

Please sign in to comment.