Announcement

Collapse
No announcement yet.

postMain() does not seem to execute in ver 11.3

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • postMain() does not seem to execute in ver 11.3

    The following code sends the debugPrintln to the output window just fine in ver 10.6 but not in ver 11.3 so I assume that postMain() is not executed when exiting the script in ver 11.3.

    Is this so, or am I missing something?

    If not, is there a way to remove global variables from memory when exiting an efs script in ver 11.3?

    PHP Code:
    function postMain(){
        
    debugPrintln ("removing " globalValueName("QQECondition_"));

        
    removeGlobalValue(globalValueName("QQECondition_"));
    }
    //globalValueName() just adds the symbol and getInvokerID() to the variable name. 
    I have only tried it with ver 11.3 so I don't know if previous versions have the same issue.

    Wayne

  • #2
    I just installed the new 11.3... ver and will test it.

    Wayne

    Comment


    • #3
      The new version doesn't execute postMain() either.
      When you remove the script from the chart or change symbols it should execute postMain() but doesn't. For the following script, this leaves the global variable in memory which causes conflicts.

      My test script:

      PHP Code:
      debugClear();
      var 
      bInit false;
      var 
      ySymbol null;
      var 
      GBLVal 33;
      //var GBLVal = "ABC";
      function main() {
          
          if (
      bInit == false) {
              
      ySymbol getSymbol()+"_"+getInterval()+"_";
              
      setGlobalValue(globalValueName("test_"),GBLVal);
              
      debugPrintln ("Loaded GblVar: " globalValueName("test_"));//Outputs to "Formula Output" just fine
              
      bInit true;
          }
      }


      function 
      postMain(){//doesn't seem to execute upon efs exit in ver 11.3
          
      debugClear();//doesn't clear output window
          
      debugPrintln ("removing " globalValueName("test_"));//doesn't output to "Formula Output"
          
      removeGlobalValue(globalValueName("test_"));
          
      debugPrintln ("removed " globalValueName("test_"));//doesn't output to "Formula Output"
      }

      function 
      globalValueName(a) {
          var 
      sStr ySymbol getInvokerID();
          return 
      sStr;

      Wayne
      Last edited by waynecd; 09-22-2011, 11:46 PM.

      Comment


      • #4
        Hi Wayne,

        I tested this in versions 11.2 and 11.3 and my results seem to agree with you, the postMain() is not called when an efs is removed or reloaded.

        I verified postMain is out there, a recognized function in the global name-space and can be called or executed at any time while the efs is running. Like you said, my testing also indicated postMain() is not called when an efs is removed or reloaded.

        FWIW, I used debug output only and stayed away from debugClear() function calls, clearing the debug window has mixed me up before when testing postMain() functionality.

        This function can be really important to maintain your logic when a chart reloads. I hadn't noticed it wasn't executing, thanks for the post.

        Originally posted by waynecd
        The new version doesn't execute postMain() either.

        ...

        Wayne

        Comment


        • #5
          I verified postMain is out there, a recognized function in the global name-space and can be called or executed at any time while the efs is running. Like you said, my testing also indicated postMain() is not called when an efs is removed or reloaded.
          For example:

          PHP Code:
          for (e in this) {
            
          debugPrintln(e);

          Comment


          • #6
            FWIW based on my tests postMain() does appear to execute [although it does not print debug statements - which is as intended] when the efs is reloaded or removed
            Alex

            Comment


            • #7
              Hi Alex,

              i sHould have iterated a global variable in postmain() but I didn't think of trying that. assumed debug output would have captured it similar to ver 10.6.

              thanks,
              steve

              Comment


              • #8
                Hi Steve, Alexis,

                postMain() in addition to not printing debug statements does not seem to clear variables set by setGlobalValue via removeGlobalValue().

                I say this because I use getInvokerID() as part of the variable name and after I remove the efs from the chart, the variable still exists in memory. So when I load the efs in another chart and iterate through the chart ID #s it stops at the chart ID # of the chart I removed the efs from.

                So, if the chart ID for the chart I removed the efs from is 12, when I load the efs on chart ID 13, getGlobalValue() in loop stops and returns the value for chart ID 12 and not 13.

                This is the reason I originaly found the problem. The old variable value stayed in memory and was found and called by getGlobalValue() (in a separate efs) even though the postMain() removeGlobalValue() should have erased it.

                I hope I was clear in my explanation.

                If you would, please let me know if you can duplicate this issue.

                A test efs follows:
                PHP Code:
                //debugClear();
                var bInit false;
                //var ySymbol = null;
                //var GBLVal = 33;
                var GBLVal "ABC";

                function 
                main() {
                    
                    if (
                bInit == false) {
                        
                ySymbol getSymbol()+"_"+getInterval()+"_";debugPrintln(GBLVal);
                        
                setGlobalValue(setGlobalValueName("test_"),GBLVal);
                        var 
                yy getGlobalValueName("test_");
                        
                debugPrintln ("13: Loaded GblVar: " +getGlobalValueName("test_")+" = "+yy);//Outputs to "Formula Output" just fine
                        
                bInit true;
                    }
                }


                function 
                postMain(){//doesn't seem to execute upon efs exit in ver 11.3
                    //debugClear();
                    
                debugPrintln ("21: removing " globalValueName("test_"));//doesn't output to "Formula Output"
                    
                removeGlobalValue(globalValueName("test_"));
                    
                debugPrintln ("23: removed " globalValueName("test_"));//doesn't output to "Formula Output"
                }

                function 
                setGlobalValueName(a) {
                    var 
                sStr ySymbol getInvokerID();
                    
                debugPrintln ("28: Loaded GblVar: " sStr);
                    return 
                sStr;
                }
                function 
                getGlobalValueName(a) {

                    for (var 
                010000i++) {
                        var 
                glblValName ySymbol i;//debugPrintln("-- "+glblValName);
                        
                getGlobalValue(glblValName);
                        if (
                != null) {
                            
                sLastGlblValName glblValName;
                            
                debugPrintln("38:-- "+sLastGlblValName);
                            return 
                v;
                        }
                    }

                    
                sLastGlblValName null;
                    return 
                null;
                }
                /*when loaded into chart ID 12 of "ES #F" with daily interval it prints the following to the Formula Output window:

                13: Loaded GblVar: ABC = ABC
                38:-- test_ES #F_D_12
                38:-- test_ES #F_D_12
                28: Loaded GblVar: test_ES #F_D_16

                then I remove the efs from chart 12 and load it into chart 13 it prints the following to the Formula Output window:

                13: Loaded GblVar: ABC = ABC
                38:-- test_ES #F_D_12
                38:-- test_ES #F_D_12
                28: Loaded GblVar: test_ES #F_D_16
                */ 
                Thanks,

                Wayne
                Last edited by waynecd; 09-26-2011, 12:53 AM.

                Comment


                • #9
                  Hi Wayne,

                  I wrote a simple efs that demonstrates that the postMain() function is called and executed in eSignal ver 11.3. It also shows that the debugPrintln() function does not work when postMain() is called on efs reload.

                  To get the efs to work, load it on the chart and continue to reload it to see output in the formula output window.

                  As for your efs, loading and removing global objects between charts based on chart ID can be challenging, especially if other charts are reloaded.

                  If you do not believe removeGlobalValue() is working, set the global variable to null. I tried to show this in my postMain() function.

                  you can also check for the existance of the function by checking if it exists in the efs global namespace with this line of code:

                  debugPrintln("test = "+("removeGlobalValue" in this));

                  Hope this helps.

                  Steve


                  PHP Code:
                  var gCount=getGlobalValue("globalCount");
                  debugPrintln("3: gCount = " gCount);

                  var 
                  bInit false;

                  function 
                  main() {
                    if (
                  bInit == false) {
                    
                  bInit true;
                   }
                  }

                  function 
                  postMain(){
                   var 
                  gCount=getGlobalValue("globalCount");
                   
                  debugPrintln("15: gCount = " gCount); // ~ works in version 10.6, not in versions 11.2 and 11.3
                   
                  if(gCount===null){
                    
                  setGlobalValue("globalCount"0);
                   }
                   else if(
                  gCount>5){
                    
                  setGlobalValue("globalCount"null);
                   }
                   else{
                    
                  gCount+=1;
                    
                  setGlobalValue("globalCount"gCount);
                   }
                  }

                  //~ debugPrintln("test = "+("removeGlobalValue" in this));

                  /* sample output copied from formula output window (bottom to top order) in eSignal ver 11.3

                  3: gCount = 0
                  3: gCount = null
                  3: gCount = 6
                  3: gCount = 5
                  3: gCount = 4
                  3: gCount = 3
                  3: gCount = 2
                  3: gCount = 1
                  3: gCount = 0
                  3: gCount = null
                  */

                  /* sample output copied from formulaoutput.log file (top to bottom order) in eSignal ver 10.6

                  3: gCount = null
                  15: gCount = null
                  3: gCount = 0
                  15: gCount = 0
                  3: gCount = 1
                  15: gCount = 1
                  3: gCount = 2
                  15: gCount = 2
                  3: gCount = 3
                  15: gCount = 3
                  3: gCount = 4
                  15: gCount = 4
                  3: gCount = 5
                  15: gCount = 5
                  3: gCount = 6
                  15: gCount = 6
                  3: gCount = null
                  15: gCount = null
                  3: gCount = 0
                  15: gCount = 0
                  3: gCount = 1
                  */ 

                  Comment


                  • #10
                    Hi Steve,

                    I have to test the effect of getInvokerID in more detail.

                    removeGlobalValue() works in postMain().

                    I appreciate your response, clarification, and the simple workaround.

                    As always, thanks.

                    Wayne
                    Last edited by waynecd; 09-26-2011, 11:08 PM.

                    Comment

                    Working...
                    X