'Acquire an exclusive lock on the currently-loaded session data.'

def acquire_lock(self, path=None):

    if (path is None):
        path = self._get_file_path()
    path += self.LOCK_SUFFIX
    while True:
        try:
            lockfd = os.open(path, ((os.O_CREAT | os.O_WRONLY) | os.O_EXCL))
        except OSError:
            time.sleep(0.1)
        else:
            os.close(lockfd)
            break
    self.locked = True
