def thread_lock(lock):
    """Return the thread lock for *lock*."""
    if hasattr(lock, '_lock'):
        return lock._lock
    elif hasattr(lock, 'acquire'):
        return lock
    else:
        raise TypeError('expecting Lock/RLock')