Open randomir opened 4 months ago
I tested your code on Ubuntu 22.04 Python 3.12 x86 and it worked fine. This is (maybe) related to how fork
works underneath in Python, though I used the same one:
import multiprocessing
multiprocessing.set_start_method("fork", force=True)
print(multiprocessing.get_start_method())
import os
import diskcache
a = diskcache.Cache(directory="/tmp/cache")
b = diskcache.Cache(directory="/tmp/cache")
os.fork()
a.get("key")
@ddorian, exactly, this works perfectly on Linux (as everything does, right?). Maybe I wasn't clear enough above, but MacOS is a necessary condition for reproduction.
Running:
on a MacOS machine, fails with:
(tested on CircleCI M1 medium instance)
AFAICT, all of the following conditions have to be met:
Cache
instances that use the same directoryCache.get()
If any of the above is removed, the snippet works are expected.
SQLite threading mode (
sqlite3.threadsafety
) is set to multi-thread ("Threads may share the module, but not connections"), so I don't think that's causing this because diskcache reconnects on forking already.Possibly related to https://github.com/grantjenks/python-diskcache/issues/266.