Skip to content

Conversation

@alensiljak
Copy link
Contributor

@alensiljak alensiljak commented May 25, 2025

With Python 3.13, using bean-price results in

dbm.sqlite3.error: unable to open database file

because shelve does not support multi-threaded access.

diskcache is a better multi-platform and multi-threaded alternative to shelve, for caching.
There is a practical difference, where the current cache file needs to be deleted, if it exists. diskcache is using a directory instead of a filename, and puts the sqlite database in there.

resolves #91

@alensiljak
Copy link
Contributor Author

alensiljak commented May 25, 2025

One item that needs to be resolved is the discrepancy between the two libraries. shelve accepts a path and creates a file, while diskcache will create a directory with the same name.
In effect, this means, if you already have a cache with the default name, diskcache will fail to create a directory with the same name.
We could add some code that checks if the path exists and it is a file, then deletes it. This would make the transition seamless for existing users.

diskcache is a better multi-platform and multi-threaded alternative to shelve, for caching. The difference is that the current cache needs to be deleted. It is using a directory instead of a filename.
@alensiljak
Copy link
Contributor Author

This should now be ready to go, if you agree.

so that a cache directory can be created.
@alensiljak
Copy link
Contributor Author

alensiljak commented Jun 3, 2025

I've been using this locally and everything seems to work fine.
Any feedback about the change?

Setting up bean-price on other devices is difficult due to links, hence it would be helpful to have this merged and published as a package at some point.

@alensiljak alensiljak changed the title Replacing shelve with diskcache Resolve sqlite3.OperationalError (replacing shelve with diskcache) Jun 3, 2025
@bastidest
Copy link

This resolves #91 for me.

@Boelensman1
Copy link

Any updates on this?

@xuhcc xuhcc merged commit ef581f8 into beancount:master Sep 7, 2025
1 check passed
@alensiljak alensiljak deleted the cache branch September 8, 2025 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache causing SQLite error on Python3.13

5 participants