Skip to content

PyInterpreterState_Head(), PyThreadState_Next() etc can't be sanely used #70648

Closed

Description

@fijall
mannequin
BPO 26461
Nosy @pitrou, @vstinner, @serhiy-storchaka
Superseder
  • bpo-1021318: PyThreadState_Next not thread safe
  • 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 = <Date 2020-05-15.01:09:24.636>
    created_at = <Date 2016-02-29.23:19:10.947>
    labels = []
    title = "PyInterpreterState_Head(), PyThreadState_Next() etc can't be sanely used"
    updated_at = <Date 2020-05-15.01:09:24.635>
    user = 'https://bugs.python.org/fijall'

    bugs.python.org fields:

    activity = <Date 2020-05-15.01:09:24.635>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-15.01:09:24.636>
    closer = 'vstinner'
    components = []
    creation = <Date 2016-02-29.23:19:10.947>
    creator = 'fijall'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 26461
    keywords = []
    message_count = 4.0
    messages = ['261030', '261031', '261032', '368894']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'vstinner', 'fijall', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '1021318'
    type = None
    url = 'https://bugs.python.org/issue26461'
    versions = []

    Activity

    1. fijall commented on Feb 29, 2016

      fijallmannequin
      MannequinAuthor

      All the internal uses of this API guard everything with HEAD_LOCK/HEAD_UNLOCK that's not exposed. It's not safe to traverse the whole API without holding those locks and those locks are static and module local

    2. vstinner commented on Feb 29, 2016

      @vstinner
      Member

      Are you asking to expose the lock?

    3. vstinner commented on Feb 29, 2016

      @vstinner
      Member

      fijal explained on IRC his use case: implement vmprof on Windows, a statistical profiler, using a C thread running in the Python process.

      The _PyThread_CurrentFrames() API requires to be called with the GIL hold which is not acceptable for his use case. Having to wait for the GIL would serialize statistics plots and so would have a poor quality, probably similar to cProfile.

      The use case is to implement something like _PyThread_CurrentFrames() without holding the GIL.

      --

      fijal mentioned pystate.c/.h functions which come with this comment:

      /* Routines for advanced debuggers, requested by David Beazley.
      Don't use unless you know what you are doing! */

      These functions are not safe if you don't hold head_mutex lock, but this lock is private in pystate.c (declared with "static").

      I guess that they are safe to use if the whole process is stopped by a debugger like gdb.

    4. vstinner commented on May 15, 2020

      @vstinner
      Member

      Duplicate of bpo-1021318.

    5. transferred this issue fromon Apr 10, 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

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions