bpo-40390: Implement channel_send_wait for subinterpreters by benedwards14 · Pull Request #19715 · python/cpython
Thanks for working on this! Overall the implementation seems good. I've left some comments on things to address.
Regarding the approach to providing a blocking "send()"... After having seen the block-in-the-function approach here, I still have reservations about it. There's a lot of value to keeping the "send" part separate from the "wait" part.
Here are some alternatives that offer that separation:
- return an acquired
threading.Lockwhich the receiving interpreter releases - return a
wait(timeout=None)function which the receiving interpreter will un-block - caller passes in an acquired lock that the receiving interpreter releases
- caller passes in a callback function that the receiving interpreter triggers (via
_Py_AddPendingCall())
My preference is that first one (return a lock). Since we are crossing the interpreter boundary we need to be extra careful. A user-defined callback is too risky. Of the remaining options the first one is simplest and most consistent conceptually.
FWIW, I expect that most of the code in this PR should still work mostly as-is.