@contextmanager
def progress_lock(max_wait_time=5):
    try:
        sleep_time = 0
        lock = 'progress.lock'
        while True:
            if os.path.isfile(lock):
                if (sleep_time > max_wait_time):
                    try:
                        os.remove(lock)
                        break
                    except:
                        continue
                else:
                    random_number = (random.random() * 0.1)
                    sleep_time += random_number
                time.sleep(random_number)
            else:
                break
        with open(lock, 'w'):
            pass
        (yield)
    finally:
        try:
            os.remove(lock)
        except:
            pass
@contextmanager
def progress_lock(max_wait_time=5):
    try:
        sleep_time = 0
        lock = 'progress.lock'
        while True:
            if os.path.isfile(lock):
                if (sleep_time > max_wait_time):
                    try:
                        os.remove(lock)
                        break
                    except:
                        continue
                else:
                    random_number = (random.random() * 0.1)
                    sleep_time += random_number
                time.sleep(random_number)
            else:
                break
        with open(lock, 'w'):
            pass
        (yield)
    finally:
        try:
            os.remove(lock)
        except:
            pass