[英]File lock (flock) compatibility between C and Python
Does the python implementation of flock work transparently along with standard C libraries? flock的python实现是否与标准C库一起透明地工作? If I have two programs, one in Python and the other in C, trying acquire a lock on a single file will it work?
如果我有两个程序,一个在Python中,另一个在C中,尝试获取单个文件的锁定它会起作用吗?
Quick links: 快速链接:
Python's fcntl
library is built directly on top of the standard C libraries; Python的
fcntl
库直接构建在标准C库之上; so on Linux fcntl.flock()
uses the flock
C function directly . 所以在Linux上,
fcntl.flock()
直接使用flock
C函数。
See the source code for the fcntl
module : 请参阅
fcntl
模块的源代码 :
#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()
文档中也有明确说明:
fcntl.flock(fd, op)
Perform the lock operation op on file descriptor fd (file objects providing afileno()
method are accepted as well).对文件描述符fd执行锁定操作op
fileno()
也接受提供fileno()
方法的文件对象)。 See the Unix manual flock(2) for details.有关详细信息,请参阅Unix手册flock(2) 。 (On some systems, this function is emulated using
fcntl()
.)(在某些系统上,使用
fcntl()
模拟此函数。)
So yes, it'll work. 是的,它会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.