dmlc / dlpack

common in-memory tensor structure
https://dmlc.github.io/dlpack/latest
Apache License 2.0
905 stars 133 forks source link

DOC: Document that GIL must be grabbed (and Py_IsInitialized()) #140

Closed seberg closed 7 months ago

seberg commented 7 months ago

I honestly don't remember if that Py_IsInitialized wasn't just to tape over C++ related deficiencies, but I suspect there isn't much to be avoided there...

(I.e. if we take care of the GIL for the other library, we also have to do this check for them which would normally be their job.)

Closes gh-103

pitrou commented 7 months ago

I honestly don't remember if that Py_IsInitialized wasn't just to tape over C++ related deficiencies

Our experience in PyArrow (not in DLPack context) is that it's required for robust integration with C++: https://github.com/apache/arrow/blob/51817917e1436c8799ed382d160798060cd76652/python/pyarrow/src/arrow/python/common.h#L194-L199

seberg commented 7 months ago

Yeah, makes sense: If you knew it came from Python, it would be your job to store it in a way like that OwnedRef which deals with it. But the whole issue here is that we want to allow you "forget" that this came from Python...