interrupt.py
Go to the documentation of this file.
10
11from gams import *
12import sys
13
15 import time
16 time.sleep(2)
17 job.interrupt()
18
19if __name__ == "__main__":
20 non_interactive = False
21 system_directory = None
22
23 # check the first user defined cmd line arguments
24 for i in range(1, min(len(sys.argv), 3)):
25 if sys.argv[i] == "-nonInteractive":
26 non_interactive = True
27 elif not system_directory:
28 system_directory = sys.argv[i]
29
30 ws = GamsWorkspace(system_directory = system_directory)
31
32 # Use a MIP that needs some time to solve
33 ws.gamslib("circpack")
34 job = ws.add_job_from_file("circpack.gms")
35 opt = ws.add_options()
36 opt.all_model_types = "couenne"
37
38 if non_interactive:
39 import threading
40 # start thread asynchronously that interrupts the GamsJob after 2 seconds
41 threading.Thread(target=interrupt_gams, args=(job,)).start()
42 else:
43 import signal
44 # register signal to job.interrupt
45 signal.signal(signal.SIGINT, lambda signal,frame:job.interrupt() )
46
47 # start GamsJob
48 job.run(opt, output=sys.stdout)
interrupt_gams
Definition: interrupt.py:41