Skip to content

Make generator methods gen_set_name and gen_set_qualname thread-safe in free-threaded builds #133931

Description

@efimov-mikhail

Feature or enhancement

Proposal:

When my PR was reviewed, some problem was found: #133373 (comment)
But my code on _GeneratorWrapper was simply copied from gen_set_name method.

So, it seems that there is no critical section in genobject.c at all.
But there is a possibility to change name or qualname for generator/async generator/coroutine.
IMO, some simple code (Py_BEGIN_CRITICAL_SECTION and Py_END_CRITICAL_SECTION) should be added to these two methods.

Also, function object seems to have exactly the same problem.

Linked PRs

Activity

  1. xuantengh commented on May 17, 2025

    @xuantengh
    Contributor

    Also, function object seems to have exactly the same problem.

    Regarding function object, there was a discussion about the lock on the performance-critical fields that will be accessed during a function call:
    #129016 (review)

  2. self-assigned this
    on May 20, 2025
  3. added 2 commits that reference this issue on May 20, 2025
  4. added 3 commits that reference this issue on Jun 7, 2025
  5. added a commit that references this issue on Jun 19, 2025
  6. added a commit that references this issue on Jul 12, 2025
  7. added a commit that references this issue on Aug 4, 2025
  8. added a commit that references this issue on Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions