python文件锁概念

来源:互联网 发布:国家五大基础数据库 编辑:程序博客网 时间:2024/05/16 05:27

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 fcntlexcept 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()  


原创粉丝点击