X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=lockfile.py;h=1e0516bf75a340b4a15629141cdfbfb83fc3485c;hb=3f4818bf9d1f3071c4e2906896d422810b5776bc;hp=770beaa9f97e3525f55b938e09a972e3b67e0e5a;hpb=a08ca309cb5bd7971210a9247a38c9bbe376a6e6;p=python_utils.git diff --git a/lockfile.py b/lockfile.py index 770beaa..1e0516b 100644 --- a/lockfile.py +++ b/lockfile.py @@ -28,7 +28,14 @@ class LockFileContents: class LockFile(object): """A file locking mechanism that has context-manager support so you - can use it in a with statement. + can use it in a with statement. e.g. + + with LockFile('./foo.lock'): + # do a bunch of stuff... if the process dies we have a signal + # handler to do cleanup. Other code (in this process or another) + # that tries to take the same lockfile will block. There is also + # some logic for detecting stale locks. + """ def __init__( @@ -123,9 +130,10 @@ class LockFile(object): cmd = self.override_command else: cmd = ' '.join(sys.argv) + print(cmd) contents = LockFileContents( pid = os.getpid(), - cmd, + commandline = cmd, expiration_timestamp = self.expiration_timestamp, ) return json.dumps(contents.__dict__)