better portalocker

This commit is contained in:
mdipierro
2012-08-27 10:06:09 -05:00
parent 86df475ae2
commit 9c4375258b
3 changed files with 72 additions and 116 deletions
+13 -1
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# portalocker.py - Cross-platform (posix/nt) API for flock-style file locking.
# portalocker.py
# Cross-platform (posix/nt) API for flock-style file locking.
# Requires python 1.5.2 or better.
"""
@@ -141,6 +142,17 @@ class LockedFile(object):
def __del__(self):
self.close()
def read_locked(filename):
fp = portalocker.LockedFile(file, 'r')
data = fp.read()
fp.close()
return data
def write_locked(filename,data):
fp = portalocker.LockedFile(file, 'w')
data = fp.write(data)
fp.close()
if __name__=='__main__':
f = LockedFile('test.txt',mode='wb')
f.write('test ok')