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

_multiarray_umath.cp39-win_amd64.pyd Crash #19149

Closed
a2448825647 opened this issue Jun 1, 2021 · 3 comments
Closed

_multiarray_umath.cp39-win_amd64.pyd Crash #19149

a2448825647 opened this issue Jun 1, 2021 · 3 comments
Labels
Embedded Issues regarding embedded python interpreters

Comments

@a2448825647
Copy link

Embedding Python in C++. Crash process : Py_Initialize->"import numpy"->Py_Finalize->Py_Initialize->"import numpy".

Reproducing code example:

#include <Python.h>
#include <iostream>
#include <string>

int main()
{
    std::string command;
    while (true)
    {
        std::cin >> command;
        if (command == "1") {
            if (!Py_IsInitialized()) {
                Py_Initialize();
                std::cout << "Py_Initialize" << std::endl;
                PyRun_SimpleString("import sys");
                PyRun_SimpleString("sys.path.append('./')");
                PyRun_SimpleString("sys.path.append('D:/Document/VSProj/PythonVM/Scripts/')");
                PyRun_SimpleString("sys.path.append('D:/Document/VSProj/PythonVM/Scripts/yolov3')");
                PyRun_SimpleString("sys.path.append('D:/Document/VSProj/PythonVM/ThirdParty/PythonPackages')");
            }
        }
        if (command == "2") {
            if (Py_IsInitialized()) {
                Py_Finalize();
                std::cout << "Py_Finalize" << std::endl;
            }
        }
        if (command == "3") {
            std::cout << "run import numpy" << std::endl;
            PyRun_SimpleString("import numpy");
        }
        std::cout << "Input command" << std::endl;
    }
    return 0;
}

input : 1 3 2 1 3

Error message:

at 0x00007FF9753DB8E9 (_multiarray_umath.cp39-win_amd64.pyd) (located in PythonVM.exe): 0xC0000005: Access violation occurred while writing location 0x0000000000000008

NumPy/Python version information:

Numpy: 1.20.3
Python: 3.9.5
Platform: Win10
Compiler: Visual Studio 2019

1.20.3 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]

@eric-wieser eric-wieser added the Embedded Issues regarding embedded python interpreters label Jun 1, 2021
@eric-wieser
Copy link
Member

eric-wieser commented Jun 1, 2021

Numpy doesn't support being imported from multiple interpreters in a single process (even sequentially as you show there) as among other reasons it caches too many objects in static variables that can't be cleared.

Even if we fixed that, the python CAPI makes it quite challenging to implement things correctly with per-interpreter module state. An example is that there is no easy way for an tp_as_number.nb_add (aka __add__) method to obtain the relevant module state: PEP 573 only addresses regular methods, not slots.

@a2448825647
Copy link
Author

Ok.....Thanks for your reply

@andyfaff
Copy link
Contributor

This can be closed now, cp39 is no longer a target of active support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Embedded Issues regarding embedded python interpreters
Projects
None yet
Development

No branches or pull requests

3 participants