In a heavily threaded applicaiton that uses the package from more than one thread at a time, the pyOpenSSL 0.8 often makes Python 2.5 interpreter crash with the following errror message:
Fatal Python error: ceval: tstate mix-up
Abort trap: 6 (core dumped)
We have test program that crashes reliably in no time here.
There are other reports of the same issue:
Investigation revealed that it is caused by the mis-use of the key to store per-thread context. Instead, it's suggested to save the context in per-instance private data. It is safe to do this, since one object instance cannot be used in separate threads at the very same time due to SSL_CTX and libopenssl API in general not being thread-friendly. Therefore, external locking at python level is required to properly serialize access to methods of the same instance anyway. But this patch makes it safe to use different instances in different threads at the same time.
Proposed patch is attached. The patch also cleans up some of the old, now unused code.