Problems with thread state
donn at drizzle.com
Tue Jul 3 17:32:08 CEST 2001
Quoth Martin Sjgren <martin at strakt.com>:
| I'm trying to write an OpenSSL module for Python (purely in C) and I've
| run into a big problem.
| My understanding of the inner workings of Python isn't that big, so please
| help me out here.
| Seeing as a call to SSL_connect() might block, I surrounded the call to it
| by Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. I also have a wrapper
| callback for verification (i.e. I plug my callback into OpenSSL and it
| calls a Python callback residing in a Context object)... Here's my
| problem: When I call PyEval_CallObject() in my wrapper callback, python
| segfaults! Some poking around with gdb shows that somewhere, before
| PyFrame_New() is called to execute the Python callback in,
| PyThreadState_Get() returns NULL!
| When I comment out the Py_(BEGIN|END)_ALLOW_THREADS stuff, everything
| What's wrong? What do I do about it?
Prior to PyEval_CallObject(), you need to get back in line for the
Python thread you released with Py_BEGIN_ALLOW_THREADS. I do that
with PyEval_AcquireThread(PyThreadState *), and then after the
callback, PyEval_ReleaseThread(PyThreadState *). How do you get
the thread state? Not the way I do, I reckon, so I will leave
that to you.
Donn Cave, donn at drizzle.com
More information about the Python-list