Linux, fcntl, F_SETLEASE and signals

John Lenton jlenton at gmail.com
Wed Jul 21 19:03:56 CEST 2004


On Wed, 21 Jul 2004 12:27:57 -0400, Chris Green <cmg at dok.org> wrote:
> Hey folks,
> 
> Is there anyway for a signal handler in python to get the information
> from a 3 argument signal handler rather than just the signal number
> and stack frame?
> 
> I've got an application where I have to check for F_SETLEASE on a file
> in python on Linux 2.4.  What this does is tells the kernel to notify
> the current process with SIGIO that a particular file descriptor is being
> modified by another process.
> 
> >>> import fcntl
> >>> f = open(".zshrc", "r+")
> >>> fcntl.fcntl(f, fcntl.F_SETLEASE, fcntl.F_WRLCK)
> 0

would this be close enough?

Python 2.3.4 (#2, Jul  5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
>>> import ctypes
>>> libc = ctypes.cdll.LoadLibrary('/lib/libc.so.6')
>>> f = open("/home/john/.bashrc")
>>> libc.fcntl(f.fileno(), fcntl.F_SETLEASE, fcntl.F_WRLCK)
0
>>> 
>>> # now someone cats .bashrc
... I/O possible

-- 
John Lenton (jlenton at gmail.com) -- Random fortune:
bash: fortune: command not found



More information about the Python-list mailing list