-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PySequence_Fast needs new macros to be safe in a nogil world #119247
Comments
…build (#119315) Add `Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST` and `Py_END_CRITICAL_SECTION_SEQUENCE_FAST` macros and update `str.join` to use them. Also add a regression test that would crash reliably without this patch.
…eaded build (pythonGH-119315) Add `Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST` and `Py_END_CRITICAL_SECTION_SEQUENCE_FAST` macros and update `str.join` to use them. Also add a regression test that would crash reliably without this patch. (cherry picked from commit baf347d) Co-authored-by: Josh {*()} Rosenberg <[email protected]>
Hey @DinoV and @colesbury: Now that the base patch is merged, should I:
|
Hi Josh - thanks for fixing |
…readed build (GH-119315) (#119419) Add `Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST` and `Py_END_CRITICAL_SECTION_SEQUENCE_FAST` macros and update `str.join` to use them. Also add a regression test that would crash reliably without this patch. (cherry picked from commit baf347d) Co-authored-by: Josh {*()} Rosenberg <[email protected]>
@MojoVampire @colesbury In the In #119438 I added an extra macro |
…eaded build (python#119315) Add `Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST` and `Py_END_CRITICAL_SECTION_SEQUENCE_FAST` macros and update `str.join` to use them. Also add a regression test that would crash reliably without this patch.
Feature or enhancement
Proposal:
Right now, most uses of
PySequence_Fast
are invalid in a nogil context when it is passed an existinglist
;PySequence_FAST_ITEMS
returns a reference to the internal array ofPyObject*
s that can be resized at any time if other threads add or delete items,PySequence_FAST_GET_SIZE
similarly reports a size that is invalid an instant after it's reported. Similarly, if individual items are replaced without changing size, you'd have similar issues.But when the argument passed is a
tuple
(incref-ed and returned unchanged, but safe due to immutability) or any non-list
type (converted to newlist
) no lock is needed. Per conversation with Dino, going to create macros, to be called after a call toPySequence_Fast
, to conditionally lock and unlock the originallist
when applicable, while avoiding locks in all other cases, before any otherPySequence*
APIs are used.Preliminary (subject to bike-shedding) macro names are:
Py_BEGIN_CRITICAL_SECTION_SEQUENCE_FAST
Py_END_CRITICAL_SECTION_SEQUENCE_FAST
both defined in
pycore_critical_section.h
.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
Discussion occurred with Dino during CPython core sprints.
Linked PRs
The text was updated successfully, but these errors were encountered: