It wasn’t the cgi library. I don’t remember the details clearly now. I remember that I was using a library called “atomic” that depended on Cython, and Cython depended on something removed from Python in 3.12. I solved it by removing atomic. It wasn’t essential. (I don’t think it prevented any important races.)
I assume that everything that relied on Cython wouldn’t work with 3.12 for a while.
I looked at the removal list in the Python documentation, and I remembered that I saw an error that the module ‘imp’ wasn’t found and that when looking into it I found that it had been replaced by ‘importlib’. I don’t remember if that was part of the same or a different issue.