Skip to content

exec_file does not close file #239

Closed
@michaelrgibbs

Description

@michaelrgibbs

When I run exec_file in a loop, I get an error on the 509th run. Using process monitor I can see that after each call to exec_file, CloseFile is not being called.

I believe fe24ab9 fixed it in Boost Python 1.58.0 but it looks like 99022d2 reverted it for 1.59.0 and the issue is present in all versions after.

It looks as though it was changed back because of issues with Python 2.7, but the original problem with closing files still exists with Python 3.6.

Tested with 1.67.0 and Python 3.6.4.

Code used to reproduce:

#include <iostream>
#include "boost/python/detail/wrap_python.hpp"
#include "boost/python.hpp"

using namespace boost::python;

int main()
{
	int count = 0;
	Py_Initialize();

	while (count < 1000)
	{
		auto strScriptFile = "test.py";

		object main_module = import("__main__");
		dict globalDict = extract<dict>(main_module.attr("__dict__"));

		try
		{
			std::cout << "Run number: " << count << std::endl;
			exec_file(strScriptFile, globalDict);
		}
		catch (const error_already_set&)
		{
			std::cout << "Failed." << std::endl;
			break;
		}
		count++;
	}

	return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions