GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-33932: Calling Py_Initialize() twice does nothing (GH-7845) · miss-islington/cpython@546892a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/test
    • test_embed.py
  • Misc/NEWS.d/next/C API
    • 2018-06-21-15-29-59.bpo-33932.VSlXyS.rst
  • Programs
    • _testembed.c
  • Python
    • pylifecycle.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_embed.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_embed.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ def test_bpo20891(self):
229229
self.assertEqual(out, '')
230230
self.assertEqual(err, '')
231231

232+
def test_initialize_twice(self):
233+
"""
234+
bpo-33932: Calling Py_Initialize() twice should do nothing (and not
235+
crash!).
236+
"""
237+
out, err = self.run_embedded_interpreter("initialize_twice")
238+
self.assertEqual(out, '')
239+
self.assertEqual(err, '')
240+
232241

233242
if __name__ == "__main__":
234243
unittest.main()
Collapse file

‎Misc/NEWS.d/next/C API/2018-06-21-15-29-59.bpo-33932.VSlXyS.rst‎

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Calling Py_Initialize() twice does nothing, instead of failing with a fatal
2+
error: restore the Python 3.6 behaviour.
Collapse file

‎Programs/_testembed.c‎

Copy file name to clipboardExpand all lines: Programs/_testembed.c
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ static int test_bpo20891(void)
263263
return 0;
264264
}
265265

266+
static int test_initialize_twice(void)
267+
{
268+
_testembed_Py_Initialize();
269+
270+
/* bpo-33932: Calling Py_Initialize() twice should do nothing
271+
* (and not crash!). */
272+
Py_Initialize();
273+
274+
Py_Finalize();
275+
276+
return 0;
277+
}
278+
266279

267280
/* *********************************************************
268281
* List of test cases and the function that implements it.
@@ -288,6 +301,7 @@ static struct TestCase TestCases[] = {
288301
{ "pre_initialization_api", test_pre_initialization_api },
289302
{ "pre_initialization_sys_options", test_pre_initialization_sys_options },
290303
{ "bpo20891", test_bpo20891 },
304+
{ "initialize_twice", test_initialize_twice },
291305
{ NULL, NULL }
292306
};
293307

Collapse file

‎Python/pylifecycle.c‎

Copy file name to clipboardExpand all lines: Python/pylifecycle.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,11 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
895895
_PyInitError
896896
_Py_InitializeEx_Private(int install_sigs, int install_importlib)
897897
{
898+
if (_PyRuntime.initialized) {
899+
/* bpo-33932: Calling Py_Initialize() twice does nothing. */
900+
return _Py_INIT_OK();
901+
}
902+
898903
_PyCoreConfig config = _PyCoreConfig_INIT;
899904
_PyInitError err;
900905

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.