MCPcopy Index your code
hub / github.com/dgrunwald/rust-cpython / allow_threads

Method allow_threads

src/python.rs:234–246  ·  view source on GitHub ↗

Temporarily releases the GIL, thus allowing other Python threads to run.

(self, f: F)

Source from the content-addressed store, hash-verified

232
233 /// Temporarily releases the GIL, thus allowing other Python threads to run.
234 pub fn allow_threads<T, F>(self, f: F) -> T
235 where
236 F: Send + FnOnce() -> T,
237 {
238 // The `Send` bound on the closure prevents the user from
239 // transferring the `Python` token into the closure.
240 unsafe {
241 let save = ffi::PyEval_SaveThread();
242 let result = f();
243 ffi::PyEval_RestoreThread(save);
244 result
245 }
246 }
247
248 /// Evaluates a Python expression in the given context and returns the result.
249 ///

Callers 2

test_thread_exit_pyFunction · 0.80
exit_threadFunction · 0.80

Calls 1

fFunction · 0.85

Tested by 2

test_thread_exit_pyFunction · 0.64
exit_threadFunction · 0.64