Opened 8 years ago

Closed 8 years ago

#11025 closed Bugs (duplicate)

exec_file raises error if run in loop

Reported by: edward.terhaar@… Owned by: Ralf W. Grosse-Kunstleve
Milestone: To Be Determined Component: python USE GITHUB
Version: Boost 1.55.0 Severity: Problem
Keywords: file loop python script Cc:

Description

We tried to run a soak test of our code which uses boost::python, but found that after 509 runs the file could not be read. Found the cause to be boost::python not closing the FILE after an fopen. Line 91 in exec.cpp. Adding fclose(fs) after PyRun_File seemed to fix the problem. You can reproduce the problem with the following code:

int _tmain(int argc, _TCHAR* argv[])
{
            int count = 0;
            Py_Initialize();
            while (true)
            {
                        auto strScriptFile = "D:\\Scrap\\ConsoleApplication2\\SampleCustomMacroOne.py";
 
                        object main_module = import("__main__");
                        dict globalDict = extract<dict>(main_module.attr("__dict__"));
                        exec_file(strScriptFile, globalDict);
 
                        std::cout << count << endl;
                        count++;
            }
 
            return 0;
}
 

Change History (1)

comment:1 by Stefan Seefeld, 8 years ago

Resolution: duplicate
Status: newclosed

This is a duplicate of #8058

Note: See TracTickets for help on using tickets.