Description
Embedded Python code can be paused and continued in another block, which allows to access previously defined symbols and saves multiple initializations. Contributor: Michael Bussieck, January 2023
Small Model of Type : GAMS
Category : GAMS Test library
Main file : embgms04.gms
$title 'Test continuation of embedded code blocks' (EMBGMS04,SEQ=928)
$onText
Embedded Python code can be paused and continued in another block, which
allows to access previously defined symbols and saves multiple initializations.
Contributor: Michael Bussieck, January 2023
$offText
Scalar x /0/;
$onMultiR
$ifE x<>2 $abort Unexpected value in line %system.line%
* Symbol x set above is not available anymore
$ifE x<>4 $abort Unexpected value in line %system.line%
* Symbol x set above is available via save file
$ifE x<>4 $abort Unexpected value in line %system.line%
* Symbol x set above should still be available via save file
* Moving from a compile time block to a execution time block
abort$(x<>8) 'Unexpected value in line %system.line%';
* Symbol x set above should still be available
* Pausing an execution time block and continuing a execution time block
abort$(x<>16) 'Unexpected value in line %system.line%';
* Symbol x set above not available without explicit restart
* Ending an execution time block and starting a new execution time block
abort$(x<>32) 'Unexpected value in line %system.line%';
scalar session1; session1 = embeddedHandle;
scalar session2; session2 = embeddedHandle;
*The following is expected to fail - we cannot continue, if there is no paused EC
$onEcho > test.gms
Scalar x;
put_utility 'save' / '0';
scalar handle;
handle = embeddedHandle;
* This won't work because the session with handle is closed
$offEcho
$call gams test.gms lo=%GAMS.lo%
$ifE errorLevel=0 $abort Expected problem in line %system.line%