Nick Coghlan <> added the comment:

Adding a bit of context from my prior email discussion with Hartmut: CPython 
actually reads sys.warnoptions at the end of Py_Initialize (its the last thing 
we do before the function returns).

It also reads sys._xoptions during startup, since that's one way of enabling 
settings like dev mode and UTF-8 mode.

That means that even though PySys_AddWarnOption and PySys_AddXOption weren't 
documented as being safe to call before Py_Initialize, they likely *won't* have 
the desired effect if an embedding application defers calling them until later, 
and their absence from the list of "safe to call before Py_Initialize" 
functions was itself a documentation bug.

For 3.8, I'd hoped that the resolution might be as simple as a hard requirement 
on embedding applications to call PyRuntime_Initialize() before doing 
*anything* with the C API, but including the "internal/pystate.h" header and 
adding a call to _PyRuntime_Initialize() wasn't enough to keep the draft test 
case in my patch from segfaulting :(


Python tracker <>
Python-bugs-list mailing list

Reply via email to