summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_embed.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-30 21:05:00 (GMT)
committerGitHub <noreply@github.com>2017-11-30 21:05:00 (GMT)
commitb4d1e1f7c1af6ae33f0e371576c8bcafedb099db (patch)
tree857873eca2c22a51524b53fb54e30ea9f66f66d7 /Lib/test/test_embed.py
parent986375ebde0dd5ff2b7349e445a06bd28a3a8ee2 (diff)
downloadcpython-b4d1e1f7c1af6ae33f0e371576c8bcafedb099db.zip
cpython-b4d1e1f7c1af6ae33f0e371576c8bcafedb099db.tar.gz
cpython-b4d1e1f7c1af6ae33f0e371576c8bcafedb099db.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_embed.py')
-rw-r--r--Lib/test/test_embed.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 8d44543..c7f45b5 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -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()