On this page
fcntl.flock
Prev: fcntl.fcntl | Up: fcntl | Next: fcntl.ioctl
Rel: fcntl.fcntl, fcntl.ioctl, fcntl.lockf
Ref: docs.python.org — fcntl.flock
Tags: #public #python3 #stdlib #fcntl
Import
import fcntl
from fcntl import flock
Signature & Overview
fcntl.flock(fd, operation, /)
Perform the lock operation on file descriptor fd.
Usage
import fcntl
import tempfile
with tempfile.TemporaryFile("w+") as f:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
fcntl.flock(f, fcntl.LOCK_UN)
Gotchas
- Unix-only advisory lock: Only works cooperatively with other processes that also call
flock(); on Windows usemsvcrt.locking()orfilelock.
REPL Inspect
from fcntl import flock
help(flock)
Linked from
Related notes
- tuts/python3/stdlib_module/fcntl/fcntl Linked here; links to this page; shared tags: #fcntl, #stdlib
- tuts/python3/stdlib_module/fcntl/ioctl Linked here; links to this page; shared tags: #fcntl, #stdlib
- tuts/python3/stdlib_module/fcntl/lockf Linked here; links to this page; shared tags: #fcntl, #stdlib
- tuts/python3/stdlib_module/fcntl links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib