(py: Python, f: F)
| 18 | } |
| 19 | |
| 20 | pub fn with_context<F, R>(py: Python, f: F) -> R |
| 21 | where |
| 22 | F: FnOnce() -> R + Send, |
| 23 | R: Send, |
| 24 | { |
| 25 | let id = CTX.with(|ctx| ctx.borrow_mut().store()); |
| 26 | let r = py.allow_threads(f); |
| 27 | CTX.with(|ctx| ctx.borrow_mut().restore(id)); |
| 28 | r |
| 29 | } |
| 30 | |
| 31 | struct Context { |
| 32 | thread: *mut ffi::PyThreadState, |