From 1423162ad4c9e5da8eaf9abc736b3eab47096a21 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 27 Jun 2015 19:26:36 +0200 Subject: [PATCH] Call PyEval_InitThreads() in module initializer to ensure it's safe to spawn rust threads in the extension module and acquire the GIL from those threads. --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 28433451..e2f0a4ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -210,6 +210,7 @@ pub unsafe fn py_module_initializer_impl( ) { abort_on_panic!({ let py = Python::assume_gil_acquired(); + ffi::PyEval_InitThreads(); let module = ffi::Py_InitModule(name, ptr::null_mut()); if module.is_null() { return; } @@ -266,6 +267,7 @@ pub unsafe fn py_module_initializer_impl( ) -> *mut ffi::PyObject { abort_on_panic!({ let py = Python::assume_gil_acquired(); + ffi::PyEval_InitThreads(); let module = ffi::PyModule_Create(def); if module.is_null() { return module; }