atexit and KeyboardInterrupt (Python)

212 views
Skip to first unread message

Fabien Tricoire

unread,
Apr 25, 2016, 1:46:48 PM4/25/16
to Gurobi Optimization
Hi,

I am looking for a reliable way to execute code when a Python program solving LPs with Gurobi is interrupted with CTRL-C. Two possible ways to do that in Python are (i) by handling KeyboardInterrupt exceptions or (ii) by using the atexit Python module and atexit.register(). While this works for simple Python programs with one call to Gurobi for solving a MIP, it does not work reliably in a more complex program with callbacks and multiple calls to optimize() for LPs (not MIPs). I have tried both ways, both work sometimes but usually not (depending on when I press CTRL-C). What am I missing?

cheers,
Fabien Tricoire
Reply all
Reply to author
Forward
0 new messages