This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Threading Bug or misuse of the api ?
Type: crash Stage:
Components: None Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Rob.Watson, loewis
Priority: normal Keywords:

Created on 2010-09-19 23:04 by Rob.Watson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg116891 - (view) Author: Rob Watson (Rob.Watson) Date: 2010-09-19 23:04
Is the below a bug or a misuse of the api ? This was compiled with visual studio 2008 and python26 64bit

void testfunction()
{
	for (int x = 1;x <= 100000;x++)
	{
		
		PyGILState_STATE gstate = PyGILState_Ensure();
		PyRun_SimpleString("2 + 1");
		PyGILState_Release(gstate);
	}	
}


int main()
{
	
	Py_Initialize();
	PyEval_InitThreads();
	PyEval_ReleaseLock();	
	
	boost::thread(boost::bind(testfunction));
	
        // if this Sleep(100) is commented out, I will get "Python Fatal Error : This thread state must be current when releasing"
	Sleep(100);
	testfunction();
	Sleep(1000000);
}
msg116892 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-09-19 23:53
Please include a message when closing an issue to indicate why it's closed.

AFAICT, this is indeed incorrect usage of the API: you should have used PyEval_SaveThread instead of PyEval_ReleaseLock.
msg116894 - (view) Author: Rob Watson (Rob.Watson) Date: 2010-09-19 23:58
it seemed changing PyEval_ReleaseLock() to PyThreadState_DeleteCurrent() has fixed my problem. Thanks
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54109
2010-09-19 23:59:01loewissetresolution: not a bug
2010-09-19 23:58:00Rob.Watsonsetresolution: not a bug -> (no value)
messages: + msg116894
2010-09-19 23:53:25loewissetresolution: not a bug

messages: + msg116892
nosy: + loewis
2010-09-19 23:25:55Rob.Watsonsetstatus: open -> closed
2010-09-19 23:22:50Rob.Watsonsetstatus: closed -> open
2010-09-19 23:22:36Rob.Watsonsetresolution: not a bug -> (no value)
2010-09-19 23:14:32Rob.Watsonsetstatus: open -> closed
resolution: not a bug
2010-09-19 23:04:11Rob.Watsoncreate