GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [subinterpreters] Don't share Python objects between interpreters · Issue #84713 · python/cpython

[subinterpreters] Don't share Python objects between interpreters #84713

New issue
Copy link
New issue
Copy link
Closed
Closed
[subinterpreters] Don't share Python objects between interpreters#84713
Copy link
Labels
3.9 (EOL)end of lifeend of lifetopic-subinterpreters

Description

@vstinner
vstinner
opened on May 6, 2020
Issue body actions
BPO 40533
Nosy @vstinner, @ericsnowcurrently, @shihai1991
PRs
  • [WIP] bpo-40533: Make PyObject.ob_refcnt atomic in subinterpreters #19958
  • bpo-40533: Disable GC in subinterpreters #19961
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-05-06.15:11:35.602>
    labels = ['expert-subinterpreters', '3.9']
    title = "[subinterpreters] Don't share Python objects between interpreters"
    updated_at = <Date 2022-01-13.17:32:56.034>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2022-01-13.17:32:56.034>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Subinterpreters']
    creation = <Date 2020-05-06.15:11:35.602>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40533
    keywords = ['patch']
    message_count = 8.0
    messages = ['368262', '368274', '368276', '368279', '380105', '388966', '408606', '410499']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'eric.snow', 'shihai1991']
    pr_nums = ['19958', '19961']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40533'
    versions = ['Python 3.9']

    Activity

    1. vstinner commented on May 6, 2020

      @vstinner
      vstinner
      on May 6, 2020
      MemberAuthor
      More actions

      To get one GIL per interpreter (bpo-40512), either PyObject.ob_refcnt member must become an atomic variable, or subinterpreters must not share any object.

      Right now, subinterpreters share Python objects. For example, PyModule_Type is declared statically and so shared by all interpreters and so PyModule_Type.tp_mro tuple is accessed in parallel by multiple interpreters. If PyObject.ob_refcnt is not atomic, Py_INCREF() and Py_DECREF() are unsafe and tp_mro tuple can be destroyed whereas it is still used.

      I propose to make PyObject.ob_refcnt atomic for now, when Python is built with EXPERIMENTAL_ISOLATED_SUBINTERPRETERS macro defined. It's a temporary workaround until subinterpreters stop sharing objects.

    2. vstinner
      added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      3.9 (EOL)end of lifeend of life
      on May 6, 2020
    3. ericsnowcurrently commented on May 6, 2020

      @ericsnowcurrently
      ericsnowcurrently
      on May 6, 2020
      Member
      More actions

      Yep, before per-interpreter GIL is official we must get to the point where *no* PyObject objects are shared.

      Making PyObject.ob_refcnt atomic until then (only as part of the experiment) should be fine.

    4. vstinner commented on May 6, 2020

      @vstinner
      vstinner
      on May 6, 2020
      MemberAuthor
      More actions

      Yep, before per-interpreter GIL is official we must get to the point where *no* PyObject objects are shared.

      I would like to add: "no PyObject objects are shared in the stdlib" ;-)

    5. vstinner commented on May 6, 2020

      @vstinner
      vstinner
      on May 6, 2020
      MemberAuthor
      More actions

      New changeset d8135e9 by Victor Stinner in branch 'master':
      bpo-40533: Disable GC in subinterpreters (GH-19961)
      d8135e9

    6. vstinner
      added
      topic-subinterpreters
      and removed
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      on May 15, 2020
    7. vstinner
      changed the title [-]Subinterpreters: don't share Python objects between interpreters[/-] [+][subinterpreters] Don't share Python objects between interpreters[/+] on May 15, 2020
    8. vstinner
      added
      topic-subinterpreters
      and removed
      interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
      on May 15, 2020
    9. vstinner
      changed the title [-]Subinterpreters: don't share Python objects between interpreters[/-] [+][subinterpreters] Don't share Python objects between interpreters[/+] on May 15, 2020
    10. vstinner commented on Oct 31, 2020

      @vstinner
      vstinner
      on Oct 31, 2020
      MemberAuthor
      More actions

      For example, PyModule_Type is declared statically and so shared by all interpreters and so PyModule_Type.tp_mro tuple is accessed in parallel by multiple interpreters.

      Another example of this issue are parallel Py_INCREF/Py_DECREF calls on the tp_bases member of a type.

    11. vstinner commented on Mar 17, 2021

      @vstinner
      vstinner
      on Mar 17, 2021
      MemberAuthor
      More actions

      To get one GIL per interpreter (bpo-40512), either PyObject.ob_refcnt member must become an atomic variable, or subinterpreters must not share any object.

      The current plan is to not share any object between two interpreters, so this PR is not needed. I close my PR 19958 which marked PyObject.ob_refcnt as atomic.

    12. vstinner commented on Dec 15, 2021

      @vstinner
      vstinner
      on Dec 15, 2021
      MemberAuthor
      More actions

      Until all Python stdlib C extensions and all third-party C extensions will be modified to no longer use and define static types and will stop shared Python objects between two interpreters, we can no longer micro-optimize the comparison of two interned strings by only comparing their memory addresse. See bpo-46006.

    13. vstinner commented on Jan 13, 2022

      @vstinner
      vstinner
      on Jan 13, 2022
      MemberAuthor
      More actions

      Sharing objects between multiple interpreters can cause complex bugs leading to crashes: https://bugs.python.org/issue46070#msg410493 For this specific bug, I wrote a workaround (GH-30577).

    14. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    15. ezio-melotti
      added this to Subinterpreterson Apr 15, 2022
    16. ezio-melotti
      moved this to Todo in Subinterpreterson Apr 15, 2022
    17. vstinner commented on Nov 3, 2022

      @vstinner
      vstinner
      on Nov 3, 2022
      MemberAuthor
      More actions

      I don't have the bandwidth to work on this issue, so I just close it.

    18. vstinner
      closed this as completedon Nov 3, 2022
    19. Repository owner moved this from Todo to Done in Subinterpreterson Nov 3, 2022
    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

      3.9 (EOL)end of lifeend of lifetopic-subinterpreters

      Projects

      • Subinterpreters
        Status
        Done
        Show more project fields

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.