File locking question
Dennis Lee Bieber
wlfraed at ix.netcom.com
Mon Oct 14 20:10:21 EDT 2002
Petri Järvinen fed this fish to the penguins on Monday 14 October 2002
12:06 am:
>
> -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?
>
Can you open the file in RW mode ('r+' I believe)?
Lock
open(... 'r+')
pickle.load
seek(0)
truncate(0) # wipe out the old contents, just in case the
pickle.save # new contents would be smaller than the old
close
unlock
--
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list