PEP 741: Python Configuration C API (second version)

Pretty much all my questions here are ones the PEP did not answer. If they were answered in discussion threads then please update the PEP with a summary of the information.

There are three groups of users here:

  • embedders using Py_InitializeFromConfig()
  • other embedders (including those using Py_Main())
  • everyone else

The first group of embedders should already have the config, so they shouldn’t need a copy of it later. That they might need it implies that the initialization API is flawed. I’d rather we fix those flaws than add a new API to expose the config.

The second group doesn’t already have the config, but arguably we should make it easier for them to be in the first group. If that isn’t an option then we need to make sure they have access to all the relevant runtime state.

(For both embedder groups, exposing the config API in the stable ABI certainly adds a wrinkle, but I’d argue against a single monolithic config API.)

The third group (other users) should be able to query the current state of the runtime. If there’s some part of that state they can’t access then we should fix that. This makes even more sense if we stop using the config after initialization, i.e. copy all needed values into the runtime state during init.

If there is still value to preserving and exposing the config used during init then to me it would make sense to have something like sys.get_config() which would return a dict with the config values. That could provide a fallback to users for values that don’t have explicit API.

(I would still argue that it would be more appropriate as something like sys.get_state() and avoid any relationship with “config”.)

Yeah, we should only modify state. The config should only represent how the runtime was initialized.

This is a strong argument for adding something like _PyRuntimeState.verbose and/or PyInterpreterState.verbose. It would be a mistake to allow users to modify the config to change some behavior.

That’s something we should fix. All such values should be copied into the runtime/interpreter state during init.

If you mean PyConfig_Get() would still be used to get the value from the runtime/interpreter state, then the function name should probably use a different word than “config”.

The only value would be to core devs debugging the runtime initialization code. However, it shouldn’t be necessary even for that. We could probably get rid of it.

I’m saying, why does each interpreter need to keep information about how the runtime was initialized? That’s unnecessary duplication.

Of course, the point is irrelevant if we don’t need to preserve any config at all.

That sounds like a challenging user interface. How will a user know which parts of the runtime state are exposed via this API and which are exposed through some other existing API? Would we expose all state through the new API?

I’m saying that the parts of the runtime state are currently all tangled together, whether in the config, initialization, or finalization. This is something we’ve been working on fixing, as you know. Having a single PyInitConfig API for the different parts feels like we’re giving up on working toward a cleaner distinction between them.

Again, though, the point is irrelevant if we stop using the config after initialization. Any new API would expose state instead.

I have additional things to say about this, but I’ll do it in a separate post.

1 Like