Python implementation of OpenSSL locking callback