Skip to content

Cache causing SQLite error on Python3.13 #91

Open
@iamkroot

Description

Running --update with the latest master branch (e894c91) on Python 3.13 is giving this error-

Traceback (most recent call last):
  File "/usr/lib/python3.13/shelve.py", line 111, in __getitem__
    value = self.cache[key]
            ~~~~~~~~~~^^^^^
KeyError: '63fc5e4df4accf902a48b972b8713d01'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/dbm/sqlite3.py", line 79, in _execute
    return closing(self._cx.execute(*args, **kwargs))
                   ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139682033261440 and this is thread id 139681986561728.
Full traceback
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<REDACTED>/bin/bean-price", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "<REDACTED>/lib/python3.13/site-packages/beanprice/price.py", line 961, in main
    price_entries = sorted(price_entries, key=lambda e: e.currency)
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "<REDACTED>/lib/python3.13/site-packages/beanprice/price.py", line 595, in fetch_price
    srcprice = fetch_cached_price(source, psource.symbol, dprice.date)
  File "<REDACTED>/lib/python3.13/site-packages/beanprice/price.py", line 509, in fetch_cached_price
    timestamp_created, result_naive = _CACHE[key]
                                      ~~~~~~^^^^^
  File "/usr/lib/python3.13/shelve.py", line 113, in __getitem__
    f = BytesIO(self.dict[key.encode(self.keyencoding)])
                ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/dbm/sqlite3.py", line 89, in __getitem__
    with self._execute(LOOKUP_KEY, (key,)) as cu:
         ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/dbm/sqlite3.py", line 81, in _execute
    raise error(str(exc))
dbm.sqlite3.error: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139682033261440 and this is thread id 139681986561728.

This is likely caused by sqlite3 becoming the default backend for dbm in Python 3.13. dbm is internally used by shelve module (used for _CACHE)

Happens even at default mode of --workers=1; not exactly sure where multiple threads are coming into the picture in this case - I would assume the same thread would be doing everything.

Running with --no-cache fixes the error, but is obviously not desired.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions