Reputation: 911
Does the python implementation of flock work transparently along with standard C libraries? If I have two programs, one in Python and the other in C, trying acquire a lock on a single file will it work?
Quick links:
Upvotes: 5
Views: 1278
Reputation: 1123520
Python's fcntl
library is built directly on top of the standard C libraries; so on Linux fcntl.flock()
uses the flock
C function directly.
See the source code for the fcntl
module:
#ifdef HAVE_FLOCK
Py_BEGIN_ALLOW_THREADS
ret = flock(fd, code);
Py_END_ALLOW_THREADS
This is clearly stated in the fcntl.flock()
documentation as well:
fcntl.flock(fd, op)
Perform the lock operation op on file descriptor fd (file objects providing afileno()
method are accepted as well). See the Unix manual flock(2) for details. (On some systems, this function is emulated usingfcntl()
.)
So yes, it'll work.
Upvotes: 5