Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[subinterpreters] Static types incorrectly share some objects between interpreters #94673

Closed
Assignees
ericsnowcurrently
@ericsnowcurrently

Description

@ericsnowcurrently

While static types (PyTypeObject values) don't themselves ever change (oncePyType_Ready() has run), they do hold mutable data. This means they cannot be safely shared between multiple interpreters without a common GIL (and without state leaking between).

Mutable data:

  • the object header (e.g. refcount), as with all objects
  • otherwise immutable objects:
    • ob_type (__class__)
    • tp_base (__base__) - set byPyType_Ready() if not set
    • tp_bases (__bases__) - always set byPyType_Ready()
    • tp_mro (__mro__) - always set byPyType_Ready()
    • tp_dict (__dict__) - set byPyType_Ready() if not set
  • mutable containers:
    • tp_subclasses (__subclasses__)
    • tp_weaklist

(Seehttps://docs.python.org/3/c-api/typeobj.html#tp-slots.)
(Note thattp_cache is no longer used.)

For the object header, if PEP 683 (immortal objects) is accepted then we can make static types immortal.

For the otherwise immutable objects, we can make sure each is immortal and then we're good. Eventp_dict is fine since it gets hidden behindtypes.MappingProxyType. We'd also need to either make sure each contained item is immortal.

Fortp_subclasses we will need a per-interpreter copy, and do the proper lookup in the__subclasses__ getter. The cache could be stored onPyInterpreterState or even as a dict intp_subclasses.

Fortp_weaklist it's a similar story as fortp_subclasses. Note thattp_weaklist isn't very important for static types since they are never deallocated.

(The above is also discussed inPEP 684.)

CC@kumaraditya303

Linked PRs

Metadata

Metadata

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp