Built-in module fcntl

fcntl UNIXfile control UNIXIO control This module performs file control and IO control on file descriptors. It is an interface to the fcntl() and ioctl() routines. File descriptors can be obtained with the fileno() method of a file or socket object. The module defines the following functions:
\begin{funcdesc}{fcntl}{fd\, op\optional{\, arg}}
Perform the requested operati...
...case the
\code{fcntl()} fails, an \code{IOError} will be raised.
\end{funcdesc}

\begin{funcdesc}{ioctl}{fd\, op\, arg}
This function is identical to the \code{...
...ations are typically defined in the library module
\code{IOCTL}.
\end{funcdesc}
If the library modules FCNTL or IOCTL are missing, you can find the opcodes in the C include files sys/fcntl and sys/ioctl. You can create the modules yourself with the h2py script, found in the Demo/scripts directory. Examples (all on a SVR4 compliant system):
import struct, FCNTL
file = open(...)
rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
Note that in the first example the return value variable rv will hold an integer value; in the second example it will hold a string value.