Python 3.1 and 3.2 fail with segmentation fault when a directory in PYTHONPATH contains an empty "encodings" subdirectory. $ cd /tmp $ mkdir encodings $ PYTHONPATH=. python3.1 Segmentation fault
The problem is that a warning is emited before the _warnings module is initialized: get_filter() uses _filters which is equal to NULL. Attached patch initialize the _warnings module (but not the warnings module) before initfsencoding(). initfsencoding() is the first function loading modules (especially the encoding package) and so _warnings have to be initialized before. The patch does also fix get_filter() to avoid the crash. This fix alone is not enough to fix this issue: Python cannot start because PyErr_WarnEx() returns -1 if _warnings is not initialized yet. I tried to display the warning (Not importing directory '/tmp/encodings': missing __init__.py) but it looks to be impossible: display a warning requires that warnings is loaded, but import warnings emits the warning. warnings imports indirectly encodings (linecache -> tokenize -> codecs). I consider that avoiding the crash is enough :-) -- The encodings can be not empty: the crash occurs if there is an encoding directory is sys.path without the __init__.py file. $ mkdir encodings $ touch encodings/a $ touch encodings/b $ touch encodings/c $ PYTHONPATH=$PWD ./python Erreur de segmentation
> Ok, buildbots are happy: backported as r81383 in 3.1 My test doesn't work on Windows. We cannot delete a directory if it's the current working directory: let's try r81384. py3k commit is simpler because it uses support.test_cwd() ;-)
> This is still an issue for Windows. See my message on python-dev: your issue (with an invalid PYTHONHOME, Python exits with abort) is not related to this one, and it's not a bug (abort is not a bug).