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.
This commit is contained in:
Wessie 2013-12-21 12:01:05 +01:00
parent f276efdf32
commit e071804ea5
2 changed files with 13 additions and 2 deletions

View file

@ -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

View file

@ -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):