File tree 1 file changed +8
-12
lines changed
1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -248,32 +248,28 @@ After:
248
248
``` rust
249
249
# use pyo3 :: prelude :: * ;
250
250
# fn main () {
251
- #[cfg(not(Py_GIL_DISABLED ))]
252
- use pyo3 :: sync :: GILProtected ;
253
251
use pyo3 :: types :: {PyDict , PyNone };
254
- #[cfg(not(Py_GIL_DISABLED ))]
255
- use std :: cell :: RefCell ;
256
- #[cfg(Py_GIL_DISABLED )]
257
252
use std :: sync :: Mutex ;
258
253
259
- #[cfg(not(Py_GIL_DISABLED ))]
260
- static OBJECTS : GILProtected <RefCell <Vec <Py <PyDict >>>> =
261
- GILProtected :: new (RefCell :: new (Vec :: new ()));
262
- #[cfg(Py_GIL_DISABLED )]
263
254
static OBJECTS : Mutex <Vec <Py <PyDict >>> = Mutex :: new (Vec :: new ());
264
255
265
256
Python :: with_gil (| py | {
266
257
// stand-in for something that executes arbitrary python code
267
258
let d = PyDict :: new (py );
268
259
d . set_item (PyNone :: get (py ), PyNone :: get (py )). unwrap ();
269
- #[cfg(not(Py_GIL_DISABLED ))]
270
- OBJECTS . get (py ). borrow_mut (). push (d . unbind ());
271
- #[cfg(Py_GIL_DISABLED )]
260
+ // we're not executing python code while holding the lock, so GILProtected
261
+ // was never needed
272
262
OBJECTS . lock (). unwrap (). push (d . unbind ());
273
263
});
274
264
# }
275
265
```
276
266
267
+ If you are executing arbitrary Python code while holding the lock, then you will
268
+ need to use conditional compilation to use ` GILProtected ` on GIL-enabled python
269
+ builds and mutexes otherwise. Python 3.13 introduces ` PyMutex ` , which releases
270
+ the GIL while the lock is held, so that is another option if you only need to
271
+ support newer Python versions.
272
+
277
273
</details >
278
274
279
275
## from 0.21.* to 0.22
You can’t perform that action at this time.
0 commit comments