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

exec_file does not close file #239

Closed
michaelrgibbs opened this issue Nov 2, 2018 · 2 comments · Fixed by #372
Closed

exec_file does not close file #239

michaelrgibbs opened this issue Nov 2, 2018 · 2 comments · Fixed by #372

Comments

@michaelrgibbs
Copy link

michaelrgibbs commented Nov 2, 2018

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;
}
@LeslieGerman
Copy link

LeslieGerman commented Dec 4, 2019

Looks like there was a fix attempt in #52 and in the corresponding #53 , but the fix was reverted, see #53 (comment) .

(And BTW I encountered the same bug in boost 1.68.0 with python 3.6.7)

@palotasb-conti
Copy link

We're also having this issue with Boost Python 1.70 and Python 3.6.8.

hajokirchhoff pushed a commit to hajokirchhoff/python that referenced this issue Aug 10, 2021
…te: Using FILE* is a bad choice here because of possible exceptions, but Py_RunFile is a C function. This fix works, because Py_RunFile - as a C function - does not throw exceptions.
stefanseefeld pushed a commit that referenced this issue Aug 10, 2021
…g FILE* is a bad choice here because of possible exceptions, but Py_RunFile is a C function. This fix works, because Py_RunFile - as a C function - does not throw exceptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants