Deadlocks can often be avoided by acquiring locks in a pre-defined order or by using timeout-based techniques like lock.acquire(timeout=...).