Menu

#860 application_startup event could fail to execute scripts

5.3
closed-fixed
Scripting (2)
5
2020-08-03
2017-05-05
Yu Tang
No

OmegaT 4.1.1b.

Steps to Reproduce:

There are three scripts in scripts/application_startup folder.

test1.groovy
console.println "test1"

test2.groovy
console.println "test2"

test3.groovy
console.println "test3"

Expected Results:

Output the log in scripting console like this (with random order):

test1
test2
test3

Actual Results:

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.

Discussion

  • Yu Tang

    Yu Tang - 2017-05-05

    Hmm... now I can see the same result about entry_activated event.
    This might be a common problem with event scripts.

     
  • Briac Pilpré

    Briac Pilpré - 2017-05-05

    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.

     
  • Kos Ivantsov

    Kos Ivantsov - 2019-05-13

    I guess this one is fixed now

     
  • Briac Pilpré

    Briac Pilpré - 2019-05-17

    It is not fixed, in ScriptingWindow.executeScript(String, ScriptItem, Map<String, Object>), the method cancelCurrentScript() 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.

     
  • Aaron Madlon-Kay

    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
  • msoutopico

    msoutopico - 2020-06-22

    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
  • Briac Pilpré

    Briac Pilpré - 2020-06-24

    I think a fix to this behaviour can be implemented by using a queuing the script execution during events. See PR 46

     
    • msoutopico

      msoutopico - 2020-06-25

      Queuing sounds like a plan. Let me know if you need any help with testing.

       
  • Briac Pilpré

    Briac Pilpré - 2020-07-25

    Fixed in [092f4f1].

     
    👍
    1
  • Briac Pilpré

    Briac Pilpré - 2020-07-25
    • status: open --> open-fixed
    • assigned_to: Briac Pilpré
     
  • Aaron Madlon-Kay

    • Group: 4.1 --> 5.3
     
  • Aaron Madlon-Kay

    • status: open-fixed --> closed-fixed
     
  • Aaron Madlon-Kay

    Fixed in OmegaT 5.3.0.

     

Log in to post a comment.