1

I try to use a Python script in my C++ project in Visual Studio 2013. If I use the script one time, it works fine. But when I try to loop on it, I got this error message :

 Access violation writing location 0x0000000000000002

And here is my code :

FILE *fd = fopen("somefile", "r");

for (;;) {
    Py_Initialize();
    PyObject* PyFileObject = PyFile_FromString("test.py", "r");

    // file before returning:
    PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), "test.py", 1);
    Py_Finalize();
}

I think something is not closed but I can't find what is wrong. By the way, I'm using Python 2.7.

jotik
  • 17,044
  • 13
  • 58
  • 123
Ed Nio
  • 593
  • 2
  • 11
  • 27
  • Have you tried adding a `if (PyFileObject)` check before the `PyFile_AsFile` call? – jotik Jun 02 '16 at 06:10
  • Yes and still the same error. `Unhandled exception at 0x00000001800D6B8C (multiarray.pyd) in ConsoleApplication1.exe: 0xC0000005: Access violation writing location 0x0000000000000002.` If I use Ipython, an error is raised but it doesn't block the script. It is more like a warning that I have something missing on my computer and it will slow the process. Maybe with Visual Studio, because of this error, the script is not able to be closed. Is there any way to 'force' the closing process ? – Ed Nio Jun 02 '16 at 07:49
  • Did you ever fix the issue? – user1104939 Nov 29 '18 at 06:46

0 Answers0