mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
986375ebde
commit
b4d1e1f7c1
5 changed files with 83 additions and 8 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue