Temporarily releases the GIL, thus allowing other Python threads to run.
(self, f: F)
| 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 | /// |