From 0d20a2564a20d03e1b8a25f882157c5c910adcca Mon Sep 17 00:00:00 2001
From: hofmockel <dreagonfly@gmx.de>
Date: Sun, 19 Jan 2014 12:35:36 +0100
Subject: [PATCH] Prevent crash if python code is executed in a rocksdb
 background thread

---
 rocksdb/_rocksdb.pyx | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/rocksdb/_rocksdb.pyx b/rocksdb/_rocksdb.pyx
index 8b3e055..423f4ba 100644
--- a/rocksdb/_rocksdb.pyx
+++ b/rocksdb/_rocksdb.pyx
@@ -35,6 +35,13 @@ import errors
 cdef extern from "cpp/utils.hpp" namespace "py_rocks":
     cdef const Slice* vector_data(vector[Slice]&)
 
+# Prepare python for threaded usage.
+# Python callbacks (merge, comparator)
+# could be executed in a rocksdb background thread (eg. compaction).
+cdef extern from "Python.h":
+    void PyEval_InitThreads()
+PyEval_InitThreads()
+
 ## Here comes the stuff to wrap the status to exception
 cdef check_status(const Status& st):
     if st.ok():
-- 
GitLab