The methods attach and attach_wait fail in Python 3.13 with "PyMutex_Unlock: unlocking mutex that is not locked".
Currently, lxc_attach_python_exec calls the deprecated function PyOS_AfterFork. Python 3.7 added the functions PyOS_BeforeFork, PyOS_AfterFork_Parent and PyOS_AfterFork_Child. See https://docs.python.org/3/c-api/sys.html for details. The old function worked up to Python 3.12.
I can reproduce this bug on Fedora 42 with the following statements.
import lxc as _lxc
container = _lxc.Container("mycontainer")
container.attach_wait(_lxc.attach_run_command, ["uname", "-n"])
An Ansible connection with ansible -i hosts.ini all -m ping fails with the misleading message "Failed to create temporary directory".
[all]
mycontainer ansible_connection=community.general.lxc ansible_lxc_host=mycontainer