filecache icon indicating copy to clipboard operation
filecache copied to clipboard

Ability to access cache from multiple python instances

Open mbkupfer opened this issue 4 years ago • 6 comments

Whenever I import a module, with a cached function, in more than one python instance, I get a Resource temporarily unavailable error on the module.py.cache file.

This is a bit of a nuisance since I then have to kill the first process to let a script run. Wouldn't this be fixed by setting the optional writeback parameter for the shelve object?

mbkupfer avatar Apr 28 '21 17:04 mbkupfer

Please test and let me know if it works.

ubershmekel avatar Apr 28 '21 17:04 ubershmekel

Sure, I'll give it a try and see if anything breaks.

mbkupfer avatar Apr 28 '21 18:04 mbkupfer

Never mind, I should of carefully read the shelve documentation as it explicitly states:

The shelve module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. Unix file locking can be used to solve this, but this differs across Unix versions and requires knowledge about the database implementation used.

That said, it does allow multiple reads so maybe there is something that can be done there. I'll have to noodle it over some more.

mbkupfer avatar Apr 28 '21 18:04 mbkupfer

@ubershmekel it doesn't appear that concurrent read/write access will work and/or fit with the intention of your filecache library. Have you considered a more robust key-value pair storage other than the built-in shelve module?

mbkupfer avatar May 03 '21 21:05 mbkupfer

Not really. At the time it felt like I should use the included batteries. Nowadays it seems that's a bit of an unreasonable requirement. It might make sense to update the underlying storage mechanism.

ubershmekel avatar May 05 '21 06:05 ubershmekel

I've also hit this issue and I expected the fail_silently argument to disable caching in such a scenario. However, this also does not let the second instance of the program run while the first is within the decorated method.

mjstahlberg avatar Oct 11 '22 13:10 mjstahlberg