From e071804ea5550bfee19a55332345b887744bbdae Mon Sep 17 00:00:00 2001 From: Wessie Date: Sat, 21 Dec 2013 12:01:05 +0100 Subject: [PATCH] Fixed the issue of the default database not being imported. Fixed a bug in the SQL database pertaining to the use of grouper. Made SQLDatabase pickleable, for better multiprocessing support. --- dejavu/database.py | 4 ++++ dejavu/database_sql.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dejavu/database.py b/dejavu/database.py index b0bfc4a..5903541 100755 --- a/dejavu/database.py +++ b/dejavu/database.py @@ -164,3 +164,7 @@ def get_database(database_type=None): return db_cls raise TypeError("Unsupported database type supplied.") + + +# Import our default database handler +import dejavu.database_sql diff --git a/dejavu/database_sql.py b/dejavu/database_sql.py index 03c8ad6..a93b1f9 100644 --- a/dejavu/database_sql.py +++ b/dejavu/database_sql.py @@ -1,5 +1,5 @@ from __future__ import absolute_import -from itertools import izip_longest +from itertools import izip_longest, ifilter import Queue import MySQLdb as mysql @@ -302,10 +302,17 @@ class SQLDatabase(Database): # (sid, db_offset - song_sampled_offset) yield (sid, offset - mapper[hash]) + def __getstate__(self): + return (self._options,) + + def __setstate__(self, state): + self._options, = state + self.cursor = cursor_factory(**self._options) + def grouper(iterable, n, fillvalue=None): args = [iter(iterable)] * n - return izip_longest(fillvalue=fillvalue, *args) + return (ifilter(None, values) for values in izip_longest(fillvalue=fillvalue, *args)) def cursor_factory(**factory_options):