There is a place in a python script where I want to wait for a second.
So I tried IJ.wait(1000). This resulted in an error which appears in the screenshot (I could not copy the text of the output or error windows) However, if I do import time time.sleep(1) it works fine. What have I done wrong in using the IJ.wait() function? tnx in advance --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html mcjbhmagciaphfpi.png (217K) Download Attachment |
Hi Aryeh,
in my view, the code for IJ.wait is so simple there can't be anything wrong with it: https://github.com/imagej/imagej1/blob/master/ij/IJ.java#L758 The only problem that can imagine is python not waiting for the command to finish, possibly because there is no output that it waits for (it is a void method). If this is the case, it would indicate that there can be also other race conditions with controlling ImageJ from Python. Which Python interface are you using, Jython, pyimagej, or something else? The ImageJ page on Python https://imagej.net/Python has a remark on possible bugs and problems; maybe this is one of them. If the Python-ImageJ interface has such a problem, this could also explain your problem with IJ.renameResult mentioned in your second mail. Then, it would be also likely that image processing via sequential "IJ.run(...)" commands from python can fail. If this is a real problem and there is no other solution (Python users, any ideas???), I could imagine a workaround using java reflection, adding a method that calls a void IJ method with a given name via Java reflection and returns a dummy result. Then, python users would have to call that method instead of directly calling the IJ method. Michael ________________________________________________________________ On 21.07.19 18:53, Aryeh Weiss wrote: > There is a place in a python script where I want to wait for a second. So I tried IJ.wait(1000). > > This resulted in an error which appears in the screenshot (I could not copy the text of the output or error windows) > > However, if I do > import time > time.sleep(1) > > it works fine. > > What have I done wrong in using the IJ.wait() function? > > tnx in advance > --aryeh > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Aryeh Weiss
Hi Michael
Thank you for your reply. I am running Jython using the built in script editor. I suspect a similar problem with the IJ.renameResults() method, where I need to put in a delay after using that, and it varies between macos and windows. I have not succeeded in creating a minimal script that reproduces the problem with IJ.renameResults(), so I realize that it will be hard to expect a fix unless more people experience it an we can assemble a better understanding of what causes it. I try to use non-global methods that explicitly return values (eg, an ImagePlus or a table or whatever), but I do not always find way to do that. Wayne wrote to me concerning the IJ.renameResults() issue, suggesting that I use Table.* methods, but while Table.* shows up in the macro, I do not see it in the API. Best regards, --aryeh On 22/07/2019 17:02, Michael Schmid wrote: > Hi Aryeh, > > in my view, the code for IJ.wait is so simple there can't be anything > wrong with it: > https://github.com/imagej/imagej1/blob/master/ij/IJ.java#L758 > > The only problem that can imagine is python not waiting for the > command to finish, possibly because there is no output that it waits > for (it is a void method). If this is the case, it would indicate that > there can be also other race conditions with controlling ImageJ from > Python. > > Which Python interface are you using, Jython, pyimagej, or something else? > > The ImageJ page on Python > https://imagej.net/Python > has a remark on possible bugs and problems; maybe this is one of them. > > > Michael > ________________________________________________________________ > On 21.07.19 18:53, Aryeh Weiss wrote: >> There is a place in a python script where I want to wait for a >> second. So I tried IJ.wait(1000). >> >> This resulted in an error which appears in the screenshot (I could >> not copy the text of the output or error windows) >> >> However, if I do >> import time >> time.sleep(1) >> >> it works fine. >> >> What have I done wrong in using the IJ.wait() function? >> >> tnx in advance >> --aryeh >> > -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Schmid
Hi Aryeh, Michael, everyone,
I am able to reproduce the problem with IJ.wait in Jython, using both the ImageJ2 Script Editor and the ImageJ1 text editor. I have not dug in deeply to understand why it happens yet, though. It might be a bug in Jython itself. The workaround of using the time module, or Thread.sleep directly, avoids the issue. Michael Schmidt wrote: > The ImageJ page on Python has a remark on possible bugs and problems; > maybe this is one of them. That remark is a caution about pyimagej, as opposed to Jython. But of course there can always be bugs. Regards, Curtis -- Curtis Rueden LOCI software architect - https://loci.wisc.edu/software ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden Have you tried the Image.sc Forum? https://forum.image.sc/ On Mon, Jul 22, 2019 at 9:39 AM Michael Schmid <[hidden email]> wrote: > Hi Aryeh, > > in my view, the code for IJ.wait is so simple there can't be anything > wrong with it: > https://github.com/imagej/imagej1/blob/master/ij/IJ.java#L758 > > The only problem that can imagine is python not waiting for the command > to finish, possibly because there is no output that it waits for (it is > a void method). If this is the case, it would indicate that there can be > also other race conditions with controlling ImageJ from Python. > > Which Python interface are you using, Jython, pyimagej, or something else? > > The ImageJ page on Python > https://imagej.net/Python > has a remark on possible bugs and problems; maybe this is one of them. > > If the Python-ImageJ interface has such a problem, this could also > explain your problem with IJ.renameResult mentioned in your second mail. > > Then, it would be also likely that image processing via sequential > "IJ.run(...)" commands from python can fail. > > If this is a real problem and there is no other solution (Python users, > any ideas???), I could imagine a workaround using java reflection, > adding a method that calls a void IJ method with a given name via Java > reflection and returns a dummy result. Then, python users would have to > call that method instead of directly calling the IJ method. > > Michael > ________________________________________________________________ > On 21.07.19 18:53, Aryeh Weiss wrote: > > There is a place in a python script where I want to wait for a > second. So I tried IJ.wait(1000). > > > > This resulted in an error which appears in the screenshot (I could > not copy the text of the output or error windows) > > > > However, if I do > > import time > > time.sleep(1) > > > > it works fine. > > > > What have I done wrong in using the IJ.wait() function? > > > > tnx in advance > > --aryeh > > > > -- > 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 |