bisect of main for bug.py with each local python builds get me to commit b127e70a8a682fe869c22ce04c379bd85a00db67 "bpo-46070: Fix asyncio initialization guard (GH-30423)" as the one that fixed bug.py most of the time.
At times I can make bug.py segfault be it on python 3.9, 3.10 or main branch. It is pretty hard (I can have a batch of 200 runs without an issue) but seems easier to reproduce with a CPU stressed, then I can have two segfaults in a batch of 50 runs.
Bash:
for i in {1..50}; do ./python ../python-crash-kodi/bug.py ; done
or sh:
for i in `seq 1 50`; do ./python ../python-crash-kodi/bug.py ; done
with:
stress -c `nproc --all` at the same time.