Skip to content

The PyOS_* hooks interact poorly with subinterpreters #104668

Closed

Description

@brandtbucher

PyOS_InputHook and PyOS_ReadlineFunctionPointer are globally-registered input hooks that have no way of recovering module-level state for the extensions that registered them. In practice, extensions like readline and tkinter get around this by using global state, which obviously isn't subinterpreter-friendly.

What's more, extensions without advertised subinterpreter support (like readline and tkinter) who register these hooks might find themselves called from within a subinterpreter (where their extension hasn't even been loaded). That's definitely a situation we want to avoid.

It seems like the best solution for 3.12 is to only call these hooks from the main interpreter, which makes the bad situation quite a bit better. If libraries really need better APIs that work per-interpreter and have ways to access module state, we can certainly add them later (but for now maybe we'll just cross our fingers and hope that nobody actually cares).

@ericsnowcurrently, how does this sound to you?

Linked PRs

Activity

  1. added
    type-bug
    interpreter-core
    3.12
    on May 19, 2023
  2. self-assigned this
    on May 19, 2023
  3. added
    3.13
    on May 22, 2023
  4. added a commit that references this issue on May 22, 2023
  5. added a commit that references this issue on May 22, 2023
  6. added a commit that references this issue on May 23, 2023
  7. ericsnowcurrently commented on May 25, 2023

    @ericsnowcurrently
    Member

    Thanks for getting this sorted out, @brandtbucher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.123.13interpreter-coretopic-C-APItopic-subinterpreterstopic-tkintertype-bug

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions