Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to reproduce callback lifetime error #281

Draft
wants to merge 1 commit into
base: latest
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions python/tests/test_scip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()