Description
'$call.AsyncNC' starts a job in a new, minimized console. With 'JobHandle' one gets the process ID of that job and the put_utility 'WinMsg' sends an interrupt signal to that PID. On Unix we get the list of PIDs using the utility pstree and send a interrupt signal to these processes. Contributor: Lutz Westermann
Small Model of Type : GAMS
Category : GAMS Test library
Main file : asynntrp.gms
$title Start GAMS job asynchronously and send interrupt signal to it (ASYNNTRP,SEQ=585)
$onText
'$call.AsyncNC' starts a job in a new, minimized console. With 'JobHandle' one
gets the process ID of that job and the put_utility 'WinMsg' sends an interrupt
signal to that PID. On Unix we get the list of PIDs using the utility pstree and
send a interrupt signal to these processes.
Contributor: Lutz Westermann
$offText
$ifThen %system.filesys% == UNIX
$call which pstree > /dev/null 2>&1
$if errorlevel 1 $abort.noError Under Unix we require the pstree utility
$set sedcmd
$set pstree pstree -p
$if LEX==%system.platform% $set sedcmd sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/'
$ifThen.DEX DEX==%system.platform%
$ set sedcmd sed 's/^.*- /(/g' | grep '^(' | cut -f 1 -d ' ' | sed 's/(//g'
$ set pstree pstree pid
$endIf.DEX
$ifThen.DAX DAX==%system.platform%
$ set sedcmd sed 's/^.*- /(/g' | grep '^(' | cut -f 1 -d ' ' | sed 's/(//g'
$ set pstree pstree pid
$endIf.DAX
$if "x%sedcmd%"==x
$abort.noError pstree output requires stream editing. Please specify command to extract a list of pids
$endIf
$call gamslib -q dicex
$onEcho > dicexx.gms
$include dicex.gms
scalar sstat; sstat = diceU.solvestat;
$offEcho
$call.AsyncNC =gams dicexx mip=cplex gdx=diceout lo=2 threads=1
$eval jh JobHandle
display$sleep(0.5) 'Wait for cplex to get started';
file fx;
while(JobStatus(%jh%)=1,
$$ifThen %system.filesys% == UNIX
put_utility fx 'shell' / "%pstree% %jh% | %sedcmd% | xargs kill -2 > /dev/null 2>&1"
$$else
put_utility fx 'winmsg' / '___GAMSMSGWINDOW___%jh%' / "GAMS Message Interrupt";
$$endIf
if(JobStatus(%jh%)=1, display$sleep(0.5) 'Wait before next try';);
);
display$sleep(1) 'Wait a sec';
execute 'test -f diceout.gdx || sleep 10'
scalar sstat; execute_load 'diceout' sstat;
abort$(sstat<>%solveStat.userInterrupt%) 'Wrong status code', sstat;