← All notes

Python fcntl: file and I/O control on Unix descriptors

Answer: The fcntl module performs file and I/O control on Unix file descriptors.

What the module is for

It is a Python interface to the Unix fcntl and ioctl routines.

Every function takes a file descriptor as its first argument.

That argument may be an integer, or an object that provides a fileno method.

The module is available on Unix, and it is not available on WASI.

Errors, locks, and platform constants

Operations that used to raise IOError now raise OSError.

flock performs a lock operation on a file descriptor.

lockf is essentially a wrapper around the fcntl locking calls.

On macOS, F_GETPATH obtains the path of a file from a file descriptor.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, fcntl — The fcntl and ioctl system calls; CPython, fcntl documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, fcntl — The fcntl and ioctl system calls; CPython, fcntl documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:4p9dp7xh

iinventedlight. 2026. "Python fcntl: file and I/O control on Unix descriptors." iinventedlight Library, iil:note:4p9dp7xh, version of 2026-11-24. https://iinventedlight.com/library/notes/python-fcntl/. License: CC-BY-4.0.

@misc{iil_note_4p9dp7xh,
  author = {{iinventedlight}},
  title = {{Python fcntl: file and I/O control on Unix descriptors}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-24},
  url = {https://iinventedlight.com/library/notes/python-fcntl/},
  note = {Permanent ID iil:note:4p9dp7xh. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-fcntl.md.