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