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.
精彩评论