Expose locking API to the python bindings. #4315

This adds a new function which exports a context manager for a
HTCondor-style file lock.