Commit a634795a authored by Matt Traudt's avatar Matt Traudt
Browse files

Add docstrings to DirectoryLock and FileLock

parent 84c9dd17
......@@ -29,6 +29,18 @@ class _FLock:
class DirectoryLock(_FLock):
'''
Holds a lock on a file in **dname** so that other sbws processes/threads
won't try to read/write while we are reading/writing in this directory.
>>> with DirectoryLock(dname):
>>> # do some reading/writing in dname
>>> # no longer have the lock
Note: The directory must already exist.
:param str dname: Name of directory for which we want to obtain a lock
'''
def __init__(self, dname):
assert os.path.isdir(dname)
lock_fname = os.path.join(dname, '.lockfile')
......@@ -36,6 +48,16 @@ class DirectoryLock(_FLock):
class FileLock(_FLock):
'''
Holds a lock on **fname** so that other sbws processes/threads
won't try to read/write while we are reading/writing this file.
>>> with FileLock(fname):
>>> # do some reading/writing of fname
>>> # no longer have the lock
:param str fname: Name of the file for which we want to obtain a lock
'''
def __init__(self, fname):
lock_fname = fname + '.lockfile'
super().__init__(lock_fname)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment