Re: locking files on Linux

2012-10-19 Thread andrea crotti
2012/10/18 Oscar Benjamin oscar.j.benja...@gmail.com: The lock is cooperative. It does not prevent the file from being opened or overwritten. It only prevents any other process from obtaining the lock. Here you open the file with mode 'w' which truncates the file instantly (without checking

Re: locking files on Linux

2012-10-19 Thread Nobody
On Thu, 18 Oct 2012 14:44:27 +0100, andrea crotti wrote: Uhh I see thanks, I guess I'll use the good-old .lock file (even if it might have some problems too). In which case, you don't see. A lock file is also advisory, i.e. it only affects applications which explicitly check for a lock file.

Re: locking files on Linux

2012-10-18 Thread Grant Edwards
On 2012-10-18, andrea crotti andrea.crott...@gmail.com wrote: I'm trying to understand how I can lock a file while writing on it, because I might have multiple processes working on it at the same time. I found the fcntl.lockf function but if I do this: In [109]: locked = open('locked.txt',

Re: locking files on Linux

2012-10-18 Thread andrea crotti
2012/10/18 Grant Edwards invalid@invalid.invalid: On 2012-10-18, andrea crotti andrea.crott...@gmail.com wrote: File locks under Unix have historically been advisory. That means that programs have to _choose_ to pay attention to them. Most programs do not. Linux does support mandatory

Re: locking files on Linux

2012-10-18 Thread Oscar Benjamin
On 18 October 2012 14:44, andrea crotti andrea.crott...@gmail.com wrote: 2012/10/18 Grant Edwards invalid@invalid.invalid: On 2012-10-18, andrea crotti andrea.crott...@gmail.com wrote: File locks under Unix have historically been advisory. That means that programs have to _choose_ to pay

Re: locking files on Linux

2012-10-18 Thread Grant Edwards
On 2012-10-18, andrea crotti andrea.crott...@gmail.com wrote: 2012/10/18 Grant Edwards invalid@invalid.invalid: On 2012-10-18, andrea crotti andrea.crott...@gmail.com wrote: File locks under Unix have historically been advisory. That means that programs have to _choose_ to pay attention to

Re: locking files on Linux

2012-10-18 Thread Oscar Benjamin
On 18 October 2012 15:49, andrea crotti andrea.crott...@gmail.com wrote: 2012/10/18 Grant Edwards invalid@invalid.invalid: If what you're guarding against is multiple instances of your application modifying the file, then either of the advisory file locking schemes or the separate lock file

Re: locking files on Linux

2012-10-18 Thread andrea crotti
2012/10/18 Oscar Benjamin oscar.j.benja...@gmail.com: Why not come up with a test that actually shows you if it works? Here are two suggestions: 1) Use time.sleep() so that you know how long the lock is held for. 2) Write different data into the file from each process and see what you end

Re: locking files on Linux

2012-10-18 Thread Oscar Benjamin
On 18 October 2012 16:08, andrea crotti andrea.crott...@gmail.com wrote: 2012/10/18 Oscar Benjamin oscar.j.benja...@gmail.com: Why not come up with a test that actually shows you if it works? Here are two suggestions: 1) Use time.sleep() so that you know how long the lock is held for. 2)