From fe56b6a4a559d47a57be70e9d78068872ab8f4e0 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 20 Jul 2023 11:42:00 -0600 Subject: [PATCH 1/2] Only set the deprecated global variables at runtime init. --- Objects/unicodeobject.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index f543c0a65b49f6..0f02d137922282 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15178,10 +15178,13 @@ init_fs_codec(PyInterpreterState *interp) /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors global configuration variables. */ - if (_Py_SetFileSystemEncoding(fs_codec->encoding, - fs_codec->errors) < 0) { - PyErr_NoMemory(); - return -1; + if (_Py_IsMainInterpreter(interp)) { + + if (_Py_SetFileSystemEncoding(fs_codec->encoding, + fs_codec->errors) < 0) { + PyErr_NoMemory(); + return -1; + } } return 0; } From 6af14a6d6663b02c79a0811f7486b7872ca21579 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 20 Jul 2023 12:21:45 -0600 Subject: [PATCH 2/2] Add a NEWS entry. --- .../2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst new file mode 100644 index 00000000000000..82312718cd047e --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst @@ -0,0 +1,4 @@ +Python no longer crashes due to an infrequent race in setting +``Py_FileSystemDefaultEncoding`` and ``Py_FileSystemDefaultEncodeErrors`` +(both deprecated), when simultaneously initializing two isolated +subinterpreters. Now they are only set during runtime initialization.