Skip to content

bpo-33932: Calling Py_Initialize() twice does nothing #7845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ def test_bpo20891(self):
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Calling Py_Initialize() twice does nothing, instead of failing with a fatal
error: restore the Python 3.6 behaviour.
14 changes: 14 additions & 0 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ static int test_bpo20891(void)
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.
Expand All @@ -288,6 +301,7 @@ static struct TestCase TestCases[] = {
{ "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 }
};

Expand Down
5 changes: 5 additions & 0 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
_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;

Expand Down