Problems with thread state
Martin Sjögren
martin at strakt.com
Wed Jul 4 02:38:48 EDT 2001
On Tue, Jul 03, 2001 at 03:32:08PM -0000, Donn Cave wrote:
> Quoth Martin Sjgren <martin at strakt.com>:
>
> | 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!
>
> 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.
This is how I do it, in my MySSL_Connection_connect()
if (PySocketSock_connect(self->socket, args) == NULL)
return NULL;
setup_ssl(self); // creates a BIO and some stuff
Py_BEGIN_ALLOW_THREADS
ret = SSL_connect(self->ssl);
Py_END_ALLOW_THREADS
// handle ret, etc
But... SSL_connect may call a callback I've set, for verification
purposes. This function looks somewhat like this:
// find context and certificate and stuff
argv = Py_BuildValue(...);
ret = PyEval_CallObject(ctx->verify_callback, argv);
Py_DECREF(argv);
// handle ret, etc
and this is where it crashes... Should I put in a PyThreadState pointer in
my ctx objects that I set instead of using BEGIN_ALLOW_THREADS, so I can
release and re-acquire around the CallObject?
Thanks a lot for your help
--
Martin Sjögren
martin at strakt.com ICQ : 41245059
Phone: +46 (0)31 405242 Cell: +46 (0)739 169191
GPG key: http://www.strakt.com/~martin/gpg.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 248 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20010704/9c873299/attachment.sig>
More information about the Python-list
mailing list