-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
gh-126366: Make native generators thread safe #126371
base: main
Are you sure you want to change the base?
Conversation
cc @colesbury |
I will try to take a look at today :) |
list.__init__
Closing in favor of #120327 |
Wait I closed my PR in favour of yours... 😆 @ZeroIntensity |
Ah! I'll reopen this and list you as a co-author if yours has merge conflicts. |
@@ -1104,8 +1104,10 @@ dummy_func( | |||
(Py_TYPE(receiver_o) == &PyGen_Type || Py_TYPE(receiver_o) == &PyCoro_Type) && | |||
((PyGenObject *)receiver_o)->gi_frame_state < FRAME_EXECUTING) | |||
{ | |||
_PyInterpreterFrame *gen_frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling you'll need to fix the specializations too. But right now they aren't enabled, so no way to test them until Matt re-enables them :(.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL at GH-127426 and #127426 (comment) now. I think we're good for the specializations.
This reverts commit f8b06ae.
int exc, int closing) | ||
{ | ||
PySendResult result; | ||
Py_BEGIN_CRITICAL_SECTION(gen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we start to put locks, maybe other functions would deserve that lock as well:
- _PyGen_yf()
- gen_close()
- _gen_throw()
- _gen_getframe()
What about these getters?
- gen_getrunning()
- gen_getsuspended()
In frameobject.c, see frame_is_suspended() (should be safe).
In ceval.c, see clear_gen_frame().
PyGenObject *gen = (PyGenObject *)receiver_o; | ||
_PyInterpreterFrame *gen_frame = &gen->gi_iframe; | ||
Py_BEGIN_CRITICAL_SECTION(gen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about _SEND_GEN_FRAME, YIELD_VALUE, _FOR_ITER_GEN_FRAME and RETURN_GENERATOR instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need to mess with things like YIELD_VALUE
. A thread can't yield another thread's generator, can it?
Edit: Well, actually, I'll check. Sending to a generator that's yielding might break things.
Co-authored-by: Victor Stinner <vstinner@python.org>
…nsity/cpython into list-init-thread-safety
…it-thread-safety
Co-authored-by: Ken Jin kenjin@python.org
ChainMap
of aCounter
in threads #126366