Amir Michail wrote: > Hi, > > Trying to open a file for writing that is already open for writing > should result in an exception. > > It's all too easy to accidentally open a shelve for writing twice and > this can lead to hard to track down database corruption errors. > > Amir I've never done this in anger so feel free to mock (a little :-).
I'd have a fixed field at the beginning of the field that can hold the hostname process number, and access time of a writing process, togeher with a sentinal value that means "no process has access to the file". A program would: 1. wait a random time. 2. open for update the file 3. read the locking data 4. If it is already being used by another process then goto 1. 5. write the process's locking data and time into the lock field. 6 Modify the files other fields. 7 write the sentinal value to the locking field. 8. Close and flush the file to disk. I have left what to do if a process has locked the file for too long as a simple exercise for you ;-). - Paddy. -- http://mail.python.org/mailman/listinfo/python-list