Changeset 13826


Ignore:
Timestamp:
Oct 23, 2019 4:06:23 PM (3 weeks ago)
Author:
molsson
Message:

Merged revision(s) 13776-13777 from branches/dev-jk-2483:
#5843 Added safeties to make sure external function executables are removed.
........
#5843 Added comments to r13776.
........

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalFunctionExecutableGenerated.java

    r13719 r13826  
    1717    @Override
    1818    public void remove() {
    19         new File(executable).delete();
     19        File file = new File(executable);
     20        boolean success = file.delete();
     21        // The first attempt to delete may fail if the process has not terminated yet.
     22        // Possibly not necessary since LiveExternalFunction.destroyProcess() now calls ProcessCommunicator.teardown().
     23        if (!success) {
     24            try {
     25                Thread.sleep(10); // Sleep some arbitrary duration to give the process time to die.
     26            } catch (InterruptedException e) {
     27                // Ignore
     28            }
     29            success = file.delete();
     30        }
    2031    }
    2132}
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ExternalFunctionImpl.java

    r13719 r13826  
    4545            setup(ext, values, timeout, com);
    4646            evaluate(ext, values, timeout, com);
    47             return teardown(timeout, com);
     47            return com.teardown(timeout);
    4848        } finally {
    4949            if (com != null) {
     
    7979        com.accept("READY");
    8080        com.cancelTimer();
    81     }
    82 
    83     public int teardown(int timeout, ProcessCommunicator<V, T> com) throws IOException {
    84         com.startTimer(timeout);
    85         com.check("EXIT");
    86         com.accept("END");
    87         int result = com.end();
    88         com.cancelTimer();
    89         // log().debug("SUCCESS TEARDOWN");
    90         return result;
    9181    }
    9282
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/LiveExternalFunction.java

    r13719 r13826  
    4646            compiler.log().debug("Finished evaluating live external function, time: " + time + "ms");
    4747        } catch (ProcessCommunicator.AbortConstantEvaluationException e) {
    48 
     48            // TODO What does this mean?
    4949        } catch (ConstantEvaluationException e) {
    5050            destroyProcess();
     
    8989        if (com != null) {
    9090            livingCachedExternals.remove(this);
    91             com.destroy();
     91            try {
     92                com.teardown(100); // TODO Should we check the return value?
     93            } catch (IOException e) {
     94                // TODO Do we need to do anything here?
     95            }
     96            com.destroy(); // TODO Do we still need to call destroy() if teardown is successful?
    9297            com = null;
    9398        }
  • trunk/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/common/evaluation/ProcessCommunicator.java

    r12940 r13826  
    4949    private String getLine() throws IOException {
    5050        String line = buffLine;
    51         if (line == null)
     51        if (line == null) {
    5252            line = in.readLine();
     53        }
    5354        if (line == null) {
    5455            if (timeOutHappened) {
     
    110111            String format = deserializeString();
    111112            String value = deserializeString();
    112             if (warning != 0)
     113            if (warning != 0) {
    113114                mc.log().warning("%s: " + format, name, value);
    114             else
     115            } else {
    115116                mc.log().verbose("%s: " + format, name, value);
     117            }
    116118            line = getLine();
    117119        }
     
    133135            super(null, string);
    134136        }
     137    }
     138
     139    public int teardown(int timeout) throws IOException {
     140        startTimer(timeout);
     141        check("EXIT");
     142        accept("END");
     143        int result = end();
     144        cancelTimer();
     145        return result;
    135146    }
    136147
Note: See TracChangeset for help on using the changeset viewer.