You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
_PyCoreConfig: add stdio_encoding and stdio_errors #78666
Currently, the code to select the encoding and error handler of sys.stdin, sys.stdout and sys.stderr is run later in Py_Initialize(). I propose to move most of this code into _PyCoreConfig_Read() and add stdio_encoding and stdio_errors to _PyCoreConfig to easily let Python embedders to select the encoding.
Attached PR implements this idea. During Py_Initialize(), the code still reads the LC_CTYPE locale to choose the error handler if stdio_errors is NULL. This check cannot be done earlier, since the LC_CTYPE locale is only set to the user locale in Py_Initialize(): after _PyCoreConfig_Read().
The Py_SetStandardStreamEncoding() function has been added by Nick Coghlan in bpo-16129.
This new pre-initialization API allows embedding
applications like Blender to force a particular
encoding and error handler for the standard IO streams.
Yeah, there were some good reasons I went with the relatively brute force option of provideding Blender with a new config API call back in bpo-16129 - as we've seen, actually fixing it properly has been a multi-year multi-person effort :)
Yeah, there were some good reasons I went with the relatively brute force option of provideding Blender with a new config API call back in bpo-16129 - as we've seen, actually fixing it properly has been a multi-year multi-person effort :)
Yeah, I see ;-) Thanks for Py_SetStandardStreamEncoding(), it fixed Blender use case!
Activity
vstinner commentedon Aug 23, 2018
Currently, the code to select the encoding and error handler of sys.stdin, sys.stdout and sys.stderr is run later in Py_Initialize(). I propose to move most of this code into _PyCoreConfig_Read() and add stdio_encoding and stdio_errors to _PyCoreConfig to easily let Python embedders to select the encoding.
Attached PR implements this idea. During Py_Initialize(), the code still reads the LC_CTYPE locale to choose the error handler if stdio_errors is NULL. This check cannot be done earlier, since the LC_CTYPE locale is only set to the user locale in Py_Initialize(): after _PyCoreConfig_Read().
The Py_SetStandardStreamEncoding() function has been added by Nick Coghlan in bpo-16129.
vstinner commentedon Aug 28, 2018
New changeset 9e4994d by Victor Stinner in branch 'master':
bpo-34485: Enhance init_sys_streams() (GH-8978)
9e4994d
vstinner commentedon Aug 28, 2018
New changeset 2c8ddcf by Victor Stinner in branch 'master':
bpo-34485: Fix _Py_InitializeCore() for C locale coercion (GH-8979)
2c8ddcf
vstinner commentedon Aug 28, 2018
New changeset 98c49c6 by Victor Stinner in branch '3.7':
bpo-34485: Fix _Py_InitializeCore() for C locale coercion (GH-8979) (GH-8981)
98c49c6
vstinner commentedon Aug 28, 2018
New changeset 124b9eb by Victor Stinner in branch 'master':
bpo-34485: Add _Py_ClearStandardStreamEncoding() (GH-8982)
124b9eb
vstinner commentedon Aug 29, 2018
New changeset 315877d by Victor Stinner in branch 'master':
bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986)
315877d
vstinner commentedon Aug 29, 2018
New changeset 0b9ea4b by Victor Stinner in branch '3.7':
[3.7] bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986) (GH-8987)
0b9ea4b
vstinner commentedon Aug 29, 2018
New changeset 177d921 by Victor Stinner in branch 'master':
bpo-34485, Windows: LC_CTYPE set to user preference (GH-8988)
177d921
vstinner commentedon Aug 29, 2018
New changeset dfe0dc7 by Victor Stinner in branch 'master':
bpo-34485: Add _PyCoreConfig.stdio_encoding (GH-8881)
dfe0dc7
vstinner commentedon Aug 29, 2018
Oh wow, I didn't expect that it would be so complicated to "just" get the encoding of sys.stdout... I had to fix many bugs to be able to do that!
vstinner commentedon Aug 29, 2018
New changeset cf21504 by Victor Stinner in branch 'master':
bpo-34485: Emit C locale coercion warning later (GH-9002)
cf21504
ncoghlan commentedon Aug 30, 2018
Yeah, there were some good reasons I went with the relatively brute force option of provideding Blender with a new config API call back in bpo-16129 - as we've seen, actually fixing it properly has been a multi-year multi-person effort :)
vstinner commentedon Aug 30, 2018
Yeah, I see ;-) Thanks for Py_SetStandardStreamEncoding(), it fixed Blender use case!
vstinner commentedon Sep 3, 2018
New changeset f01b2a1 by Victor Stinner in branch 'master':
bpo-34544: Fix setlocale() in pymain_read_conf() (GH-9041)
f01b2a1
vstinner commentedon Sep 3, 2018
New changeset 73b00be by Victor Stinner in branch 'master':
bpo-34544: pymain_read_conf() don't change LC_ALL (GH-9045)
73b00be