开发者

File Locking in Python? [duplicate]

This question already has answers here: Locking a file in Python (15 answers) Closed 9 years ago.

I want to lock the file whenever I perform read/write operation o开发者_JAVA技巧n that file. No other program or function can access file until I do not release the file. How do you do this in Python?


You can try this:

http://docs.python.org/library/fcntl.html#fcntl.flock

or this:

http://docs.python.org/library/fcntl.html#fcntl.lockf

To get file descriptor from a file-like object, you just need to call fileno method.


Google up zc.lockfile or portalocker.py. Both libraries can lock a file in a portable manner (windows and posix systems). I usually use zc.lockfile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜