From 0d10717d5d4dfb85fec8577dd79e090976c3d202 Mon Sep 17 00:00:00 2001 From: AntoinePrv Date: Thu, 11 Nov 2021 16:29:14 -0500 Subject: [PATCH] Add test to reproduce callback lifetime error --- python/tests/test_scip.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/python/tests/test_scip.py b/python/tests/test_scip.py index f610dbc1..5f1d5d9b 100644 --- a/python/tests/test_scip.py +++ b/python/tests/test_scip.py @@ -154,3 +154,23 @@ def test_is_solved(model): def test_bounds(model): assert model.dual_bound < model.primal_bound + + +@requires_pyscipopt +def test_pyscipopt_callback(model): + """GIL is properly reaquired in PySCIPOpt and PySCIPOpt model liftime is managed.""" + import pyscipopt.scip + + class EventHandler(pyscipopt.scip.Eventhdlr): + def eventinit(self): + self.model.catchEvent(scip.SCIP_EVENTTYPE.LPEVENT, self) + + def eventexit(self): + self.model.dropEvent(scip.SCIP_EVENTTYPE.LPEVENT, self) + + def eventexec(self, event): + # Use the pyscipopt object to verify its lifetime + self.model.getNTotalNodes() + + model.as_pyscipopt().includeEventhdlr(EventHandler(), "Name", "Description") + model.solve()