File locking question

Petri Järvinen jarvin24 at assari.cc.tut.fi
Mon Oct 14 03:06:30 EDT 2002


Hi,

I'm working on windowsNT platform and have run out of good ideas to
implement nicely the following procedure.

I have a case where many processes try to modify same file concurrently.

Every process wants to 
1. Read the whole text file (UnPickle)
2. Write to same, but now empty file (Pickle againg)

The problem is that when I first open the file

-lock the file with portalocker.py (LOCK_EX)
file = open('d:\inetpub\scripts\graphs\%s.graph' % (name),'r')
values = cPickle.load(file)
-Unlock the file

I must closet the file and open it to write-mode. That causes the
file-lock to be released and any process can read the dirty-values
from file before it is locked again.

So! How can I lock the file so that closing the file woudn't release
the lock?

- Petri





More information about the Python-list mailing list