Skip to content

Commit

Permalink
Use a counter instead of a Boolean to check for initialized; n calls
Browse files Browse the repository at this point in the history
to Py_Initialize will be undone by n calls to Py_Uninitialize.
  • Loading branch information
gvanrossum committed Aug 20, 1997
1 parent 558be28 commit aa61505
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Demo/pysvr/pysvr.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ main_thread(int port)
PyEval_AcquireThread(gtstate);
gtstate = NULL;
Py_Finalize();
Py_Finalize();
}
exit(0);
}
Expand Down Expand Up @@ -213,6 +214,7 @@ init_python()
if (gtstate)
return;
Py_Initialize(); /* Initialize the interpreter */
Py_Initialize(); /* Initialize the interpreter */
PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
gtstate = PyEval_SaveThread(); /* Release the thread state */
}
Expand Down
10 changes: 5 additions & 5 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ Py_Initialize()
PyObject *bimod, *sysmod;
char *p;

if (initialized)
Py_FatalError("Py_Initialize: already initialized");
initialized = 1;
if (++initialized > 1)
return;

if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1;
Expand Down Expand Up @@ -166,9 +165,10 @@ Py_Finalize()

call_sys_exitfunc();

if (!initialized)
if (--initialized > 0)
return;
if (initialized < 0)
Py_FatalError("Py_Finalize: not initialized");
initialized = 0;

tstate = PyThreadState_Get();
interp = tstate->interp;
Expand Down

0 comments on commit aa61505

Please sign in to comment.