Loading...
Searching...
No Matches
interrupt.py
Go to the documentation of this file.
9
10import argparse
11import signal
12import sys
13import threading
14import time
15from gams import GamsWorkspace
16
17
19 time.sleep(2)
20 job.interrupt()
21
22
23if __name__ == "__main__":
24 parser = argparse.ArgumentParser()
25 parser.add_argument("sysDir", nargs="?", default=None)
26 parser.add_argument("-nonInteractive", action="store_true")
27 args = parser.parse_args()
28
29 ws = GamsWorkspace(system_directory=args.sysDir)
30
31 # Use a model that needs some time to solve
32 ws.gamslib("dicex")
33 job = ws.add_job_from_file("dicex.gms")
34 opt = ws.add_options()
35 opt.all_model_types = "scip"
36
37 if args.nonInteractive:
38 # start thread asynchronously that interrupts the GamsJob after 2 seconds
39 threading.Thread(target=interrupt_gams, args=(job,)).start()
40 else:
41 # register signal to job.interrupt
42 signal.signal(signal.SIGINT, lambda signal, frame: job.interrupt())
43
44 # start GamsJob
45 job.run(opt, output=sys.stdout)
interrupt_gams
Definition: interrupt.py:39