OmegaT 4.1.1b.
There are three scripts in scripts/application_startup folder.
test1.groovy
console.println "test1"
test2.groovy
console.println "test2"
test3.groovy
console.println "test3"
Output the log in scripting console like this (with random order):
test1 test2 test3
I got the irregular log in scripting console like this:
test1 test3
or:
test3 test2
or:
test3
Sometimes I could see the error in OmegaT.log.
13967: Error: java.lang.InterruptedException 13967: Error: at java.lang.Object.wait(Native Method) 13967: Error: at java.lang.Object.wait(Unknown Source) 13967: Error: at java.awt.EventQueue.invokeAndWait(Unknown Source) 13967: Error: at java.awt.EventQueue.invokeAndWait(Unknown Source) 13967: Error: at javax.swing.SwingUtilities.invokeAndWait(Unknown Source) 13967: Error: at org.omegat.gui.scripting.ScriptRunner.invokeGuiScript(ScriptRunner.java:187) 13967: Error: at org.omegat.gui.scripting.ScriptRunner.executeScript(ScriptRunner.java:168) 13967: Error: at org.omegat.gui.scripting.ScriptRunner.executeScript(ScriptRunner.java:130) 13967: Error: at org.omegat.gui.scripting.ScriptingWindow$ScriptWorker.doInBackground(ScriptingWindow.java:556) 13967: Error: at org.omegat.gui.scripting.ScriptingWindow$ScriptWorker.doInBackground(ScriptingWindow.java:540) 13967: Error: at javax.swing.SwingWorker$1.call(Unknown Source) 13967: Error: at java.util.concurrent.FutureTask.run(Unknown Source) 13967: Error: at javax.swing.SwingWorker.run(Unknown Source) 13967: Error: at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 13967: Error: at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 13967: Error: at java.lang.Thread.run(Unknown Source)
But other times I couldn't see any errors.
Hmm... now I can see the same result about entry_activated event.
This might be a common problem with event scripts.
My guess is that it's caused by the fact that only one script can be executed at a time. To ensure this, we cancel other running script prior to a script execution.
I think the thread get canceled before having the opportunity of running the script.
I guess this one is fixed now
It is not fixed, in
ScriptingWindow.executeScript(String, ScriptItem, Map<String, Object>)
, the methodcancelCurrentScript()
is always called before executing a new script. This means that a long-running script can be canceled when a newer one is executed during the event processing.The window should probably only ever execute one script at a time, with subsequent invocations cancelling the current script.
But the event-based script execution is different; it should probably invoke sequentially.Sorry that didn't make sense. What we need is to invoke the scripts sequentially, but I'm guessing at the moment execution is async so we don't know at the invocation site when the current invocation ends.Last edit: Aaron Madlon-Kay 2019-05-17
I can reproduce this in OmegaT 4.2.0, but only when I reload the project or close it and open it again. I cannot reproduce it when OmegaT has just been launched and the first thing I do is to open the project.
Any forecast about the fix?
Last edit: msoutopico 2020-06-22
I think a fix to this behaviour can be implemented by using a queuing the script execution during events. See PR 46
Queuing sounds like a plan. Let me know if you need any help with testing.
Fixed in [092f4f1].
Fixed in OmegaT 5.3.0.