lock the first bytes of file (non-blockingtryfcntl lockf( fileno()fcntl lock_ex fcntl lock_nb except ioerror,eprint "unable to acquire lock" notes the set of available fcntl(commands and options is system-dependent the fcntl module may contain more than constants on some platforms although locking operations defined in other modules often make use of the context-manager protocolthis is not the case for file locking if you acquire file lockmake sure your code is written to properly release the lock many of the functions in this module can also be applied to the file descriptors of sockets io the io module implements classes for various forms of / as well as the built-in open(function that is used in python the module is also available for use in python the central problem addressed by the io module is the seamless handling of different forms of basic / for exampleworking with text is slightly different than working with binary data because of issues related to newlines and character encodings to handle these differencesthe module is built as series of layerseach of which adds more functionality to the last base / interface the io module defines basic / programming interface that all file-like objects implement this interface is defined by base class iobase an instance of iobase supports these basic operationsattribute description closed close( fileno( flush( isatty( readable( readline([limit]flag indicating whether or not the file is closed closes the file returns the integer file descriptor flushes the / buffers (if anyreturns true if is terminal returns true if was opened for reading reads one line from the stream limit is the maximum number of bytes to read reads all lines from and return as list limitif providedis the maximum number of bytes that can be read before stopping the actual number of bytes read will be slightly greater to accommodate the last linewhich is kept intact readlines([limit] lib fl ff