From 053fa5b9842e561a40b2d926845f8ad10f75f75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Niederb=C3=BChl?= Date: Thu, 10 Jan 2019 00:36:53 +0100 Subject: [PATCH] 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 --- tests/test_gc.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_gc.rs b/tests/test_gc.rs index acc020a2..5a102ea2 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -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)]