pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
821 stars 130 forks source link

Merely importing pygame causes abort trap on exit (Mac) #2062

Open robclewley opened 1 year ago

robclewley commented 1 year ago

Environment:

Current behavior:

This error message on every exit from a script or session after importing pygame:

pygame-ce 2.2.0 (SDL 2.0.22, Python 3.11.0)
Assertion failed: (!PyErr_Occurred()), function _PyType_Lookup, file typeobject.c, line 3832.
Abort trap: 6

Expected behavior:

No Assertion failed error!

Steps to reproduce:

Literally just import pygame then quit.

I can run that single line as a script from CLI or my IDE with or without any other following pygame commands (including pygame.init(), pygame.quit()) or directly importing from an interactive command line session in an OS terminal. Or I can run my own or anyone else's pygame code that I download. Regardless, when the session ends, that error appears.

The only mention of a similar-sounding error I've found anywhere is https://github.com/inducer/pycuda/issues/233. No idea if it's related, though. It's a pretty recent fresh installation of Python 3.9 and 3.11, but both are built using debug symbols (3.9.15-debug and 3.11-dev-debug) using pyenv and the linked issue involved a debug version of python.

novialriptide commented 1 year ago

I can confirm that I can reproduce this issue.

andrew@mac-mini desktop % pyenv exec python3 lmao.py                                                
pygame-ce 2.2.0 (SDL 2.0.22, Python 3.11.0)
Assertion failed: (!PyErr_Occurred()), function _PyType_Lookup, file typeobject.c, line 3832.
zsh: abort      pyenv exec python3 lmao.py

Here are my specifications:

CPU: Apple M1
OS:  macOS Monterey 12.5.1

After I installed Python 3.11.0-debug, these warnings came up. Perhaps they're related?

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/andrewhong/.pyenv/versions/3.11.0-debug/lib/python3.11/tkinter/__init__.py", line 38, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
    ^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/andrewhong/.pyenv/versions/3.11.0-debug/lib/python3.11/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
Starbuck5 commented 1 year ago

My hunch is that this is related to atexit stuff in src_c/base.c. So @novialriptide that might be a good place to start in trying to track this down.