[Python-Dev] working with Python threads from C extension module?
Bill Janssen
janssen at parc.com
Sat Sep 8 01:09:09 CEST 2007
Reading through the C API documentation, I find:
``This is done so that dynamically loaded extensions compiled with
thread support enabled can be loaded by an interpreter that was
compiled with disabled thread support.''
I've currently got the set-up-SSL-threading code in _ssl.c surrounded
by a "#ifdef HAVE_THREAD" bracket. It sounds like that might not be
sufficient. It sounds like I need a runtime test for thread
availability, instead, like this:
#ifdef HAVE_THREAD
if (PyEval_ThreadsInitialized())
_setup_ssl_threads();
#endif
Seem right?
So what happens when someone loads the _ssl module, initializes the
threads, and tries to use SSL? It's going to start failing again. I
think I need my own version of Py_BEGIN_ALLOW_THREADS and
Py_END_ALLOW_THREADS, don't I? Which also checks to see if the SSL
threading support has been initialized, in addition to the Python
threading support. Something like
#define SSL_ALLOW_THREADS {if (_ssl_locks != NULL) { Py_BEGIN_ALLOW_THREADS }}
#define SSL_DISALLOW_THREADS {if (_ssl_locks != NULL) { Py_BEGIN_ALLOW_THREADS }}
Any comments?
Bill
More information about the Python-Dev
mailing list