diff --git a/beets/library.py b/beets/library.py index 84ce3e154..9ad78fd1e 100644 --- a/beets/library.py +++ b/beets/library.py @@ -703,6 +703,7 @@ class Library(BaseLibrary): directory='~/Music', path_formats=None, art_filename='cover', + timeout=5.0, item_fields=ITEM_FIELDS, album_fields=ALBUM_FIELDS): if path == ':memory:': @@ -717,7 +718,8 @@ class Library(BaseLibrary): self.path_formats = path_formats self.art_filename = bytestring_path(art_filename) - self.conn = sqlite3.connect(self.path) + self.timeout = timeout + self.conn = sqlite3.connect(self.path, timeout) self.conn.row_factory = sqlite3.Row # this way we can access our SELECT results like dictionaries diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 70db77dc1..8777cdc7a 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -45,6 +45,7 @@ DEFAULT_PATH_FORMATS = { 'singleton': 'Non-Album/$artist/$title', } DEFAULT_ART_FILENAME = 'cover' +DEFAULT_TIMEOUT = 5.0 # UI exception. Commands should throw this in order to display @@ -639,12 +640,18 @@ def main(args=None, configfh=None): path_formats.update(config.items('paths')) art_filename = \ config_val(config, 'beets', 'art_filename', DEFAULT_ART_FILENAME) + lib_timeout = config_val(config, 'beets', 'timeout', DEFAULT_TIMEOUT) + try: + lib_timeout = float(lib_timeout) + except ValueError: + lib_timeout = DEFAULT_TIMEOUT db_path = os.path.expanduser(libpath) try: lib = library.Library(db_path, directory, path_formats, - art_filename) + art_filename, + lib_timeout) except sqlite3.OperationalError: raise UserError("database file %s could not be opened" % db_path) diff --git a/docs/changelog.rst b/docs/changelog.rst index 02920b060..c9bec389c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -41,6 +41,7 @@ Changelog via the ``ignore`` setting; see :doc:`/reference/config`. * The database now keeps track of files' modification times so that, during an ``update``, unmodified files can be skipped. (Thanks to Jos van der Til.) +* A new ``timeout`` config value avoids database locking errors on slow systems. * Fix a crash after using the "as Tracks" option during import. * Fix a Unicode error when tagging items with missing titles. * Fix a crash when the state file (``~/.beetsstate``) became emptied or diff --git a/docs/reference/config.rst b/docs/reference/config.rst index e87931d41..58411644a 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -98,6 +98,11 @@ section header: only in the ``import`` command). Turn this off if your terminal doesn't support ANSI colors. +``timeout`` + The amount of time that the SQLite library should wait before raising an + exception when the database lock is contended. This should almost never need + to be changed except on very slow systems. Defaults to 5.0 (5 seconds). + You can also configure the directory hierarchy beets uses to store music. That uses the ``[paths]`` section instead of the ``[beets]`` section. Each string is a `Python template string`_ that can refer to metadata fields (see below for