python文件在进行读写的时候,多进程读写的时候需要用到文件锁概念
这需要用到python兼容性编程
这里需要要到安装文件类库:
pylibs:https://github.com/tav/pylibs
tornado:http://pypi.python.org/pypi/tornado
Python兼容性编程:http://feilong.me/2011/02/learning-python-follow-felinx-part-one
python的文件锁:http://blog.csdn.net/qinxiuchen/article/details/6854684
try:
import fcntl
except ImportError:
if os.name == 'nt':
from tornado import win32_support as fcntl
else:
raise
"""
文件锁测试
"""
import time
fp = open('hello.txt','w')
fcntl.flock(fp, fcntl.LOCK_EX)
print '文件锁开始执行'
time.sleep(100)
fcntl.flock(fp, fcntl.LOCK_UN)
fp.close()