Replies: 6 comments 5 replies
-
Thank you for thinking of us and reaching out! I spent some time this evening trying to share a few of my thoughts, please feel free to ask me to elaborate on anything which you think is not well explained. |
Beta Was this translation helpful? Give feedback.
-
@encukou I've been thinking a little about sub-interpreters and PEP 489 compatibility for PyO3. I have the impression this is the way concurrency in Python is planned to evolve. As expressed in that Google doc, I'm concerned this is going to be a challenge for PyO3 to support. Am I right that at the C-API level, there will be no protections against sharing Python objects between sub-interpreters, and the rule is simply "don't do this, because refcounting (etc.) is not thread-safe"? If so, then this would make associating Python objects to a GIL an (Many Rust projects forbid usage of It may be that PyO3 ends up needing to opt-out of PEP 489 to give users a safe API surface. PyO3 and Rust projects may eventually become an obstacle to wider usage of sub-interpreters in the ecosystem if so. Some help in thinking through this would be appreciated. One way in which I could see this working, for example, would be to take some ideas of the |
Beta Was this translation helpful? Give feedback.
-
The TLDR of the above is that I think PyO3 needs one of the two following things to make itself safe in the presence of multiple interpreters:
(1) would make PyO3 sound at the type system level. The extensive redesign seems intractable, so I wonder if you think it could be possible to implement a way in the Python C API to verify if an object belongs to the current interpreter? |
Beta Was this translation helpful? Give feedback.
-
Sadly, I doubl (2) can be done in CPython without adding extra data on each object, which would meed too much extra memory. Also, where would this be called on the Rust side? On each interaction with the API? Or when retreiving a static object (where it might be possibe to have a interpreter→object map)? I guess another way is to embrace the current constraints, and make sure PyO3 is only usable in one interpreter per process. If there's an init function, make it fail the second time it's called. Or record the current interpreter at startup and check it's the only one used from Rust. |
Beta Was this translation helpful? Give feedback.
-
Sorry for dropping off this thread for such a long time, little one and other threads have been keeping me busy. Hopefully you and your family are also doing ok. I've opened #2523 to raise Wrt (2) - agreed that the overhead on every object would be too much. What if the interpreter id was recorded in the type objects? I think that would probably be sufficient to know which interpreter an object should be associated with. |
Beta Was this translation helpful? Give feedback.
-
There is now a wider effort for mapping out C API issues at: https://github.com/capi-workgroup/problems/issues |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm figuring out a strategy for the future of Python's C-API, and as one of the goals I'd like to make it friendly for non-C languages. But since I mostly deal with C & Python, I'd like to ask you for any suggestions, pain points or comments on how to better do that.
Would you like to help?
I started a Google doc to collect notes, please feel free to comment there, or here, or suggest a better place.
Thank you for your time!
Beta Was this translation helpful? Give feedback.
All reactions