[Python-Dev] Updated AutoThreadState pre-PEP
Mark Hammond
mhammond@skippinet.com.au
Fri, 14 Feb 2003 12:11:06 +1100
[Aahz, in private mail, provokes an interesting point]
> "What happens if you do PyAutoThreadState_Ensure() and
> PyEval_InitThreads() has not been called?"
>
> There should be some discussion of the appropriate time to call
> PyEval_InitThreads().
Yeah, this is an interesting, indirect point. If the author must call
PyEval_InitThreads(), then they must also have called Py_Initialize(). If
in the real world, all users of this API have already done this at process
startup, then our internal checks for initialization are pointless.
Therefore, I propose that I change the PEP to state that before the
AutoThreadState API can be used, Python must have been "correctly
initialized", where "correctly initialized" is defined as:
* Py_Initialize() has been called.
* If the extension is multi-threaded, then PyEval_InitThreads() has been
called from the "main thread".
If these conditions are not met, Python will either (and hopefully usually)
Py_FatalError(), or occasionally dead-lock.
Any objections?
Mark.