Kaydet (Commit) aa61505f authored tarafından Guido van Rossum's avatar Guido van Rossum

Use a counter instead of a Boolean to check for initialized; n calls

to Py_Initialize will be undone by n calls to Py_Uninitialize.
üst 558be283
...@@ -168,6 +168,7 @@ main_thread(int port) ...@@ -168,6 +168,7 @@ main_thread(int port)
PyEval_AcquireThread(gtstate); PyEval_AcquireThread(gtstate);
gtstate = NULL; gtstate = NULL;
Py_Finalize(); Py_Finalize();
Py_Finalize();
} }
exit(0); exit(0);
} }
...@@ -213,6 +214,7 @@ init_python() ...@@ -213,6 +214,7 @@ init_python()
if (gtstate) if (gtstate)
return; return;
Py_Initialize(); /* Initialize the interpreter */ Py_Initialize(); /* Initialize the interpreter */
Py_Initialize(); /* Initialize the interpreter */
PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */ PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
gtstate = PyEval_SaveThread(); /* Release the thread state */ gtstate = PyEval_SaveThread(); /* Release the thread state */
} }
......
...@@ -98,9 +98,8 @@ Py_Initialize() ...@@ -98,9 +98,8 @@ Py_Initialize()
PyObject *bimod, *sysmod; PyObject *bimod, *sysmod;
char *p; char *p;
if (initialized) if (++initialized > 1)
Py_FatalError("Py_Initialize: already initialized"); return;
initialized = 1;
if ((p = getenv("PYTHONDEBUG")) && *p != '\0') if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1; Py_DebugFlag = 1;
...@@ -166,9 +165,10 @@ Py_Finalize() ...@@ -166,9 +165,10 @@ Py_Finalize()
call_sys_exitfunc(); call_sys_exitfunc();
if (!initialized) if (--initialized > 0)
return;
if (initialized < 0)
Py_FatalError("Py_Finalize: not initialized"); Py_FatalError("Py_Finalize: not initialized");
initialized = 0;
tstate = PyThreadState_Get(); tstate = PyThreadState_Get();
interp = tstate->interp; interp = tstate->interp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment