Avoid race condition in gc tests

To avoid a segfault when the object is collected, disable garbage
collection for the duration of `gc_integration2`.

Closes #198
This commit is contained in:
Alexander Niederbühl 2019-01-10 00:36:53 +01:00
parent 1b4afd1102
commit 053fa5b984
1 changed files with 4 additions and 1 deletions

View File

@ -186,8 +186,11 @@ struct GCIntegration2 {}
fn gc_integration2() {
let gil = Python::acquire_gil();
let py = gil.python();
// Temporarily disable pythons garbage collector to avoid a race condition
py.run("import gc; gc.disable()", None, None).unwrap();
let inst = Py::new_ref(py, || GCIntegration2 {}).unwrap();
py_run!(py, inst, "import gc; assert inst in gc.get_objects()");
py_run!(py, inst, "assert inst in gc.get_objects()");
py.run("gc.enable()", None, None).unwrap();
}
#[pyclass(weakref)]