Question: posix fcntl module

Ignacio Vazquez-Abrams ignacio at openservices.net
Tue Aug 28 18:51:40 EDT 2001


On Tue, 28 Aug 2001, Sheila King wrote:

> Now, here's the kicker:
> If I change the fcntl.flock calls in the posixLock.py file to fcntl.lockf
> class, then I do get errors when I try the same interactive session.
> Namely:
>
> [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> from LockFile import LockFile
> >>> obj = LockFile('lock.txt')
> >>> obj.flock('LOCK_SH')
> >>> obj.flock('LOCK_UN')
> >>> obj.flock('LOCK_EX')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "posixLock.py", line 44, in flock
>     self.getWriteLock()
>   File "posixLock.py", line 28, in getWriteLock
>     fcntl.lockf(self.fd, fcntl.LOCK_EX)
> IOError: [Errno 9] Bad file descriptor
> >>> obj2 = LockFile('datafile.txt')
> >>> obj2.flock('LOCK_EX')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "posixLock.py", line 44, in flock
>     self.getWriteLock()
>   File "posixLock.py", line 28, in getWriteLock
>     fcntl.lockf(self.fd, fcntl.LOCK_EX)
> IOError: [Errno 9] Bad file descriptor
> >>>

>From the fcntl(2) man page:

"
       F_SETLK
              The lock is set (when l_type is F_RDLCK or F_WRLCK)
              or cleared (when it is F_UNLCK).  If  the  lock  is
              held by someone else, this call returns -1 and sets
              errno to EACCES or EAGAIN.
"

>From <bits/fcntl.h>:
---
#define F_RDLCK         0       /* Read lock.  */
#define F_WRLCK         1       /* Write lock.  */
#define F_UNLCK         2       /* Remove lock.  */
---

Those are the values you want to use. It looks like Python may have this one
wrong.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>






More information about the Python-list mailing list