bpo-20891: Fix PyGILState_Ensure() (#4650)

When PyGILState_Ensure() is called in a non-Python thread before
PyEval_InitThreads(), only call PyEval_InitThreads() after calling
PyThreadState_New() to fix a crash.

Add an unit test in test_embed.
This commit is contained in:
Victor Stinner 2017-11-30 22:05:00 +01:00 committed by GitHub
parent 986375ebde
commit b4d1e1f7c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 8 deletions

View file

@ -198,6 +198,16 @@ class EmbeddingTests(unittest.TestCase):
self.assertEqual(out, '')
self.assertEqual(err, '')
def test_bpo20891(self):
"""
bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
call PyEval_InitThreads() for us in this case.
"""
out, err = self.run_embedded_interpreter("bpo20891")
self.assertEqual(out, '')
self.assertEqual(err, '')
if __name__ == "__main__":
unittest.main()