Skip to content
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

[Python][C++] How to use pyarrow in the python sub-interpreter #42151

Closed
zeroRains opened this issue Jun 14, 2024 · 5 comments
Closed

[Python][C++] How to use pyarrow in the python sub-interpreter #42151

zeroRains opened this issue Jun 14, 2024 · 5 comments
Labels
Component: C++ Type: usage Issue is a user question

Comments

@zeroRains
Copy link

zeroRains commented Jun 14, 2024

Describe the usage question you have. Please include as many useful details as possible.

Hi, I want to execute the same function with different python sub-interpreter in different threads. The function codes are like that

void f(const char *tname)
{
    PyThreadState *_ts = Py_NewInterpreter();
    // sub.swap_to_self();
    std::string code = R"PY(
import pyarrow
print("TNAME gan ni niang")

a = 0
for i in range(100000000):
    a = a+1
    )PY";

    code.replace(code.find("TNAME"), 5, tname);
    PyRun_SimpleString(code.c_str());
    Py_EndInterpreter(_ts);
}

But I get a error when I import the pyarraow in the sub-interpreter

import pyarrow.lib as _lib
ImportError: module pyarrow.lib does not support loading in sub-interpreters

Dose I use the pyarrow in a wrong way? Or It dosen't allow use in the sub-interpreters?

If the later is, will it support in the future?

If it can use in sub-interpreter, how should I do?

Component(s)

python, c++

@zeroRains zeroRains added the Type: usage Issue is a user question label Jun 14, 2024
@raulcd raulcd changed the title How to use pyarrow in the python sub-interpreter [Python][C++] How to use pyarrow in the python sub-interpreter Jun 14, 2024
@raulcd
Copy link
Member

raulcd commented Jun 14, 2024

cc @pitrou

@pitrou
Copy link
Member

pitrou commented Jun 25, 2024

Unfortunately, Cython support for subinterpreters is experimental and unfinished for now (see CYTHON_USE_MODULE_STATE in http://docs.cython.org/en/latest/src/userguide/source_files_and_compilation.html#c-macro-defines).

Once Cython support is finished for it, we should probably try to enable it.

@zeroRains
Copy link
Author

I use the the subinterpreters in CPython, not in Cython. It support for subinterpreters in the latest python version. (see in https://docs.python.org/3/c-api/init.html#sub-interpreter-support)

@pitrou
Copy link
Member

pitrou commented Jun 26, 2024

PyArrow uses Cython, this is why it's not compatible with sub-interpreters.

@zeroRains
Copy link
Author

OK,I got that, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: C++ Type: usage Issue is a user question
Projects
None yet
Development

No branches or pull requests

3 participants