def refresh_lock(lock_file):
    """'Refresh' an existing lock.

    'Refresh' an existing lock by re-writing the file containing the
    owner's unique id, using a new (randomly generated) id, which is also
    returned.

    """
    unique_id = '%s_%s_%s' % (
        os.getpid(),
        ''.join([str(random.randint(0, 9)) for i in range(10)]), hostname)
    try:
        lock_write = open(lock_file, 'w')
        lock_write.write(unique_id + '\n')
        lock_write.close()
    except Exception:
        # In some strange case, this happen.  To prevent all tests
        # from failing, we release the lock, but as there is a
        # problem, we still keep the original exception.
        # This way, only 1 test would fail.
        while get_lock.n_lock > 0:
            release_lock()
        raise
    return unique_id
Refresh' an existing lock.

    'Refresh' an existing lock by re-writing the file containing the
    owner's unique id, using a new (randomly generated) id, which is also
    returned.