I've just discovered that Python2.3 has some problems (in my case, it
segfaults) if when the GIL is release but PyEval_InitThreads() has not
ben called.
Adding this code at the very begining of my pyx file seems to solve
the problem.
cdef extern from "Python.h":
enum: PY_VERSION_HEX
enum: WITH_THREAD
void PyEval_InitThreads()
if PY_VERSION_HEX < 0x02040000:
if WITH_THREAD:
PyEval_InitThreads()
However, I believe Cython/Pyrex could generate the fix somewere in the
module init function (at the begining? at the end?) if the GIL is ever
aquired/released in Cython code (I mean, using 'with gil/nogil' ?).
What do you think? As reference, you can see some comments in
'Python-2.3.6/Modules/_bsddb.c'. For your convenience, pasted below:
/* PyEval_InitThreads is called here due to a quirk in python 1.5
* - 2.2.1 (at least) according to Russell Williamson <[EMAIL PROTECTED]>:
* The global interepreter lock is not initialized until the first
* thread is created using thread.start_new_thread() or fork() is
* called. that would cause the ALLOW_THREADS here to segfault due
* to a null pointer reference if no threads or child processes
* have been created. This works around that and is a no-op if
* threads have already been initialized.
* (see pybsddb-users mailing list post on 2002-08-07)
*/
#ifdef WITH_THREAD
PyEval_InitThreads();
#endif
I really need advice here, because my Python+threads knowledge is not
really good.
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev