Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31635
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: locking files on Linux |
| Date | 2012-10-18 13:27 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <k5p03u$3t8$2@reader1.panix.com> (permalink) |
| References | <mailman.2430.1350566044.27098.python-list@python.org> |
On 2012-10-18, andrea crotti <andrea.crotti.0@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', 'w')
>
> In [110]: fcntl.lockf(locked, fcntl.LOCK_EX)
>
> I can happily open the file with vim from somewhere and write on it, so
> it doesn't seem to be very useful, or am I missing something?
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 locking, but it's rarely used and must be
manually enabled at the filesystem level. It's probably worth noting
that in the Linux kernel docs, the document on mandatory file locking
begins with a section titled "Why you should avoid mandatory locking".
http://en.wikipedia.org/wiki/File_locking#In_Unix-like_systems
http://kernel.org/doc/Documentation/filesystems/locks.txt
http://kernel.org/doc/Documentation/filesystems/mandatory-locking.txt
http://www.thegeekstuff.com/2012/04/linux-file-locking-types/
http://www.hackinglinuxexposed.com/articles/20030623.html
--
Grant Edwards grant.b.edwards Yow! Your CHEEKS sit like
at twin NECTARINES above
gmail.com a MOUTH that knows no
BOUNDS --
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 14:14 +0100
Re: locking files on Linux Grant Edwards <invalid@invalid.invalid> - 2012-10-18 13:27 +0000
Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 14:44 +0100
Re: locking files on Linux Grant Edwards <invalid@invalid.invalid> - 2012-10-18 13:57 +0000
Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 15:49 +0100
Re: locking files on Linux Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 16:04 +0100
Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-18 16:08 +0100
Re: locking files on Linux Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 16:31 +0100
Re: locking files on Linux andrea crotti <andrea.crotti.0@gmail.com> - 2012-10-19 13:15 +0100
Re: locking files on Linux Nobody <nobody@nowhere.com> - 2012-10-19 15:36 +0100
Re: locking files on Linux Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-10-18 14:58 +0100
csiph-web