locking files

Joseph Holland King insanc at cc.gatech.edu
Wed Feb 21 15:50:55 EST 2001


Christopher Lee <clee at gnwy100.wuh.wustl.edu> wrote:
: [as normal user]
:> chmod g+s tmp; chmod g-x tmp
:> python
:>> import fcntl, FCNTL
:>> fp = open("tmp", "rw")
:>> fd = fp.fileno()
:>> fcntl.lockf(fd, FCNTL.F_LOCK)  # secures the lock, prevents
:                                   # reading/writing 

following this i tried this code:

import FCNTL, fcntl

int_temp = 999999
fd = open("ftbl", "wr")
fd1 = fd.fileno()
fcntl.lockf(fd1, FCNTL.LOCK_EX)
while(int_temp > 0):
        int_temp = int_temp - 1
fcntl.lockf(fd1, FCNTL.LOCK_UN)
fd.close()

and then after did the following:
{gypsy:gte743n:116} cat mbox  > ftbl
{gypsy:gte743n:117} python testlock.py
{gypsy:gte743n:118} more ftbl

as you can see i cated my mailbox into ftbl and the ran the script the script
however empties the file. is there something in my code that is causing
this or is there something i am not doing? thank you.

-- 
Joseph Holland King  | "God whispers to us in our pleasures, speaks in our
                     |  conscience, but shouts in our pains: it is His
                     |  megaphone to rouse a deaf world." C. S. Lewis



More information about the Python-list mailing list