Message100432
_PyGILState_Init() initialize autoInterpreterState variable. This variable have to be set before the first call to PyGILState_Ensure().
The problem is that _PyGILState_Init() is called late: at the end of Py_InitializeEx(). It's called after initsite(), whereas initsite() may need to call _PyGILState_Init().
Example: add the following lines at the end of site.py:
---
import readline
import rlcompleter
readline.parse_and_bind("tab: complete")
raw_input("press TAB")
---
Run an interpreter and press TAB:
---
$ ./python
press TABpython: Python/pystate.c:595: PyGILState_Ensure: Assertion `autoInterpreterState' failed.
Abandon
---
Other example of functiions using _PyGILState_Init(): _PyObject_Dump() (useful for debug), sqlite module, os.popen*(), ctypes Python callbacks, etc.
I don't know the right place for _PyGILState_Init() in Py_InitializeEx(). _PyGILState_Init() calls the following functions:
- PyThread_get_thread_ident()
- PyThread_allocate_lock()
- PyThread_acquire_lock()
- PyThread_release_lock()
- Py_FatalError() (on error)
None of these function use Python functions, so _PyGILState_Init() can be called very early. The earliest position is just after the call to PyThreadState_New(), before PyThreadState_Swap(). It tested it and it works correctly.
If _PyGILState_Init() is called before PyThreadState_Swap(), PyThreadState_Swap() can be simplified (it doesn't need to check if GIL is initialized or not). Attached patch implement that.
--
I hit this bug when I was debuging Python: I added a call to _PyObject_Dump() which stopped Python (assertion error) because the GIL was not initialized :-/
I already hitted this bug some weeks ago when I was working on the thread state preallocation when creating a new thread: #7544. |
|
Date |
User |
Action |
Args |
2010-03-10 20:17:38 | admin | set | recipients:
+ tim.peters, loewis, amaury.forgeotdarc, pitrou |
2010-03-10 20:17:36 | admin | link | issue8063 messages |
2010-03-08 00:39:56 | vstinner | unlink | issue8063 messages |
2010-03-04 23:09:57 | vstinner | set | recipients:
+ vstinner |
2010-03-04 23:09:57 | vstinner | set | messageid: <1267744197.1.0.664779918218.issue8063@psf.upfronthosting.co.za> |
2010-03-04 23:09:55 | vstinner | link | issue8063 messages |
2010-03-04 23:09:54 | vstinner | create | |
|