[Spambayes] locking pickle/dbm against concurrent access?
Skip Montanaro
skip at pobox.com
Mon Jan 20 19:18:49 EST 2003
>>>>> "Anthony" == Anthony Baxter <anthony at interlink.com.au> writes:
>>>> Skip Montanaro wrote
>> How do you get the temp file from the real file without copying it? If I
>> understand the way things work, you'd do something like
>>
>> * copy real to temp
>> * train on new messages
>> * update temp
>> * move temp back to real (the atomic part we all want)
Anthony> I thought it'd be more like:
Anthony> * open real in read-only mode, load into memory
Anthony> * train on new messages
Anthony> * write new data out to temp
Anthony> * rename temp to real (atomically)
Perhaps, but that first step would be even more expensive than a simple
copy. I thought all the current system did was score the current message
then update only those keys necessary.
In addition, I don't think shelve allows you to open a database in read-only
mode. Oops, wait, the default is read/write. Neither shelve.open()'s
docstring nor the section in the libref manual says anything about its flag
argument. You have to RTSL to learn about it. I'll see about fixing that.
The libref docs do say:
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.
Skip
More information about the Spambayes
mailing list