Calling Py_Initialize() twice does nothing, instead of failing with a
fatal error: restore the Python 3.6 behaviour.
(cherry picked from commit
209abf746985526bce255e2fba97d3246924885d)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
self.assertEqual(out, '')
self.assertEqual(err, '')
+ def test_initialize_twice(self):
+ """
+ bpo-33932: Calling Py_Initialize() twice should do nothing (and not
+ crash!).
+ """
+ out, err = self.run_embedded_interpreter("initialize_twice")
+ self.assertEqual(out, '')
+ self.assertEqual(err, '')
+
if __name__ == "__main__":
unittest.main()
--- /dev/null
+Calling Py_Initialize() twice does nothing, instead of failing with a fatal
+error: restore the Python 3.6 behaviour.
return 0;
}
+static int test_initialize_twice(void)
+{
+ _testembed_Py_Initialize();
+
+ /* bpo-33932: Calling Py_Initialize() twice should do nothing
+ * (and not crash!). */
+ Py_Initialize();
+
+ Py_Finalize();
+
+ return 0;
+}
+
/* *********************************************************
* List of test cases and the function that implements it.
{ "pre_initialization_api", test_pre_initialization_api },
{ "pre_initialization_sys_options", test_pre_initialization_sys_options },
{ "bpo20891", test_bpo20891 },
+ { "initialize_twice", test_initialize_twice },
{ NULL, NULL }
};
_PyInitError
_Py_InitializeEx_Private(int install_sigs, int install_importlib)
{
+ if (_PyRuntime.initialized) {
+ /* bpo-33932: Calling Py_Initialize() twice does nothing. */
+ return _Py_INIT_OK();
+ }
+
_PyCoreConfig config = _PyCoreConfig_INIT;
_PyInitError err;