2015-01-05 16:05:53 +00:00
|
|
|
use ffi;
|
|
|
|
|
2015-01-04 04:50:28 +00:00
|
|
|
use std::sync::{Once, ONCE_INIT};
|
|
|
|
use std::thread::Thread;
|
2015-01-05 16:05:53 +00:00
|
|
|
|
2015-01-04 04:50:28 +00:00
|
|
|
static START: Once = ONCE_INIT;
|
2015-01-05 16:05:53 +00:00
|
|
|
|
2015-01-04 04:50:28 +00:00
|
|
|
/// Prepares the use of python in a free-threaded context.
|
|
|
|
pub fn prepare_freethreaded_python() {
|
|
|
|
START.call_once(|| unsafe {
|
|
|
|
::ffi::Py_InitializeEx(0);
|
|
|
|
if ::ffi::PyEval_ThreadsInitialized() == 0 {
|
|
|
|
::ffi::PyEval_InitThreads();
|
|
|
|
// InitThreads() will acquire the GIL,
|
|
|
|
// but we don't want to acquire it at this point
|
|
|
|
// (it's not acquired in the other code paths)
|
|
|
|
::ffi::PyEval_ReleaseLock();
|
|
|
|
}
|
|
|
|
});
|
2015-01-05 16:05:53 +00:00
|
|
|
}
|
|
|
|
|