Skip to content

datetime extension module isolation #243

Description

@neonene

PEP-687 is about to be implemented to the _datetime module.

Two approaches are proposed at present. I would like Steering Council to choose one.

  1. (regular)
    Multi-phase-init with per-module heaptypes (and C-API).
    abi: Store a reference (to the C-API struct) in PyInterpreterState.

  2. (special)
    Multi-phase-init with per-interpreter heaptypes (and C-API).
    abi: Store at least 7 heaptypes' references in PyInterpreterState.

The following shows the replacements of _datetime heaptypes (multi-phase init module) when running test_datetime in the refleak test:

main interp sequence 1.per-module 2.per-interp
import module heaptypes_A heaptypes_A
module reload (new module) heaptypes_B (new) (no change)
module reload (new module) heaptypes_C (new) (no change)
interp finish

The approach (2) avoids possible regressions1 caused by mixing modules with forbidden hacky usage23. Technically, (2) does not make sense (1) should be enough. In my opinion, unknown regressions should not be hidden by (2). Also, (2) will be a bad official example of isolation. However, there seems to be a case where maintaining (1) is not good for mental health, which is also serious.

Related issue/PR: gh-117398, gh-118357

Thanks

UPDATED: a few rewords

Footnotes

  1. https://github.com/python/cpython/issues/117398#issuecomment-2104353830

  2. https://docs.python.org/3/howto/isolating-extensions.html#surprising-edge-cases

  3. https://docs.python.org/3/library/sys.html#sys.modules

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions