加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux上的Python中不存在os.O_EXLOCK(独占锁)

发布时间:2020-12-14 00:28:39 所属栏目:Linux 来源:网络整理
导读:正如您在下面看到的,我在 Linux(RHEL)上运行 Python 2.6,但由于某种原因它没有os.O_EXLOCK.有什么理由吗?有没有办法解决这个问题? Python 2.6.5 (r265:79063,Apr 9 2010,11:16:46) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2Type "help","copyrig
正如您在下面看到的,我在 Linux(RHEL)上运行 Python 2.6,但由于某种原因它没有os.O_EXLOCK.有什么理由吗?有没有办法解决这个问题?

Python 2.6.5 (r265:79063,Apr  9 2010,11:16:46) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> import os
>>> os.O_EXLOCK
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
AttributeError: 'module' object has no attribute 'O_EXLOCK'
>>> os.O_DSYNC
4096
>>>

解决方法

如 the Python Standard Library documentation所述,

The following constants are options for the flags parameter to the
open() function. They can be combined using the bitwise OR operator |.
Some of them are not available on all platforms. For descriptions of
their availability and use,consult the open(2) manual page on Unix or
the MSDN on Windows.

O_EXLOCK originated in the BSD world;它通常不适用于Linux.您也许可以使用Python fcntl module.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读