Is there a way to pause an ImageJ macro midway through its execution and then resume it later?
John Oreopoulos Research Assistant Spectral Applied Research Richmond Hill, Ontario Canada www.spectral.ca -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi,
you can insert the waitForUser command: the macro will be stopped until pressing the OK button. Otherwise if you need a precise time-interval for the break, the wait() command could help you. Hope it helps Mario Il 12/11/2012 7:34 AM, John Oreopoulos ha scritto: > Is there a way to pause an ImageJ macro midway through its execution and then resume it later? > > > John Oreopoulos > Research Assistant > Spectral Applied Research > Richmond Hill, Ontario > Canada > www.spectral.ca > > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ---PLEASE Note the change in the email address--- -- Mario Faretta Department of Experimental Oncology European Institute of Oncology c/o IFOM-IEO Campus for Oncogenomics via Adamello 16 20139 Milan Italy Phone: ++39-0294375027 email: [hidden email] http://www.ifom-ieo-campus.it -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
I guess I meant something more along the lines of pausing at an arbitrary moment so I can halt the macro, put my laptop to sleep for a while (not off), and then resume the macro after waking the laptop up again.
John Oreopoulos On 2012-12-11, at 1:39 AM, Mario Faretta <[hidden email]> wrote: > Hi, > you can insert the waitForUser command: the macro will be stopped until pressing the OK button. Otherwise if you need a precise time-interval for the break, the wait() command could help you. > Hope it helps > Mario > > Il 12/11/2012 7:34 AM, John Oreopoulos ha scritto: >> Is there a way to pause an ImageJ macro midway through its execution and then resume it later? >> >> >> John Oreopoulos >> Research Assistant >> Spectral Applied Research >> Richmond Hill, Ontario >> Canada >> www.spectral.ca >> >> >> >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > -- > ---PLEASE Note the change in the email address--- > > -- > Mario Faretta > Department of Experimental Oncology > European Institute of Oncology > c/o IFOM-IEO Campus for Oncogenomics > via Adamello 16 20139 Milan Italy > Phone: ++39-0294375027 > email: [hidden email] > http://www.ifom-ieo-campus.it > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
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 |
Dear,
if your post was a question, this may be an answer: =============================== waitForUser(string) Halts the macro and displays string in a dialog box. The macro proceeds when the user clicks "OK". Unlike showMessage, the dialog box is not modal, so the user can, for example, create a selection or adjust the threshold while the dialog is open. To display a multi-line message, add newline characters ("\n") to string. This function is based on Michael Schmid's Wait_For_User plugin. Example: WaitForUserDemo. waitForUser(title, message) This is a two argument version of waitForUser, where title is the dialog box title and message is the text dispayed in the dialog. waitForUser This is a no argument version of waitForUser that displays "Click OK to continue" in the dialog box. =============================== Regards Herbie :::::::::::::::::::::::::::::::: Am 30.04.17 um 18:33 schrieb LP: > 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 > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Pause-resume-macro-tp5001108p5018641.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by LP
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 |
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 |
Free forum by Nabble | Edit this page |