Login  Register

Re: Pause/resume macro?

Posted by George Patterson on May 01, 2017; 7:42pm
URL: http://imagej.273.s1.nabble.com/Pause-resume-macro-tp5001108p5018646.html

Hi LP,
For all the reasons Micheal Schmid discussed, this is probably not a good
idea and the multiple instances of ImageJ is probably the best bet.
However, if you use Herbie and Mario's suggestions along with the isKeyDown
function, you might get a way to pause your macro "semi-arbitrarily".
Placing the following lines at a few places, such as at the beginnings or
at the ends of loops, in your macro might work.

if(isKeyDown("alt")==true){
waitForUser("Pause macro", "Waiting on you to do your thing");
setKeyDown("none");
}

Again, this is a limited approach and might work for pausing, but keep the
earlier warnings about unintended consequences in mind.
George



On Sun, Apr 30, 2017 at 2:12 PM, Michael Schmid <[hidden email]>
wrote:

> Hi LP,
>
> in some cases, you can do other things in ImageJ while a macro is running,
> but in general this is not a safe way of working.
> In principle you could write a short plugin or Javascript that suspends
> the thread of the currently running macro or all running macros (all
> threads whose names start with "Run$"), and resume the thread(s) later.
> This is NOT a safe way of operation! Your 'do something else' operation
> may leave ImageJ in a state that is different from what the macro expects.
> For non-Batch-mode macros, already selecting a new foreground image will
> usually make them work in an unintended way, not to mention changes of
> ImageJ settings.
> Also some operations may fail if they are suspended in one thread, and
> another thread uses the same type of operation. In other words, there is
> still some code in ImageJ1 and in many ImageJ1 plugins that does not work
> correctly with multithreading (e.g. use of static class variables as
> parameters, having them static to save their values as defaults for the
> next invocation of the command). This is problem remains if one of the
> threads is suspended.
>
> So, the only safe way of doing something else while a macro is running is
> starting another instance of ImageJ. Depending on the operating system, you
> may have an Edit>Options>Misc 'Run Single-Instance Listener' option that
> you can disable. Also starting ij.jar from the command line can give you a
> new instance of ImageJ. If CPU load is an issue, on Unix-like operating
> systems, you may suspend the process of the ImageJ instance running the
> macro, and resume it later:
>   kill -TSTP processID
>   kill -CONT processID
> where processID is the PID of ImageJ as you get it via 'ps'
>
>
> Michael
> ________________________________________________________________
>
> On 2017-04-30 18:33, LP wrote:
>
>> Dear All,
>>
>> I think that John Oreopoulos (Dec 11, 2012) had a very good question:
>>
>> Can we pause a macro at an arbitrary moment so we can do something else,
>> and
>> then resume the macro later?
>>
>> This topic has more than 2370 views so I assume that many people wondered
>> the same thing.
>>
>>
>> Thank you
>>
>>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html