Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Philipp Hanslovsky
    @hanslovsky
    Maybe a simpler example would be better. In case of N5, I would only replace Thread.currentThread.getContextClassLoader() with CompressionAdapter.class.getClassLoader(). The scenario is auto-detection of compression types and compression parameters, similar to autodetection of plugins and services in ImageJ. My naive though is that changing the classloader in N5 fixed the problem in kscript and maybe the same would be true for the problems that I observe in kscript with ImageJ. But I am probably even less of an expert in classloaders than you, so I am trying to figure out why the context classloader is used and what the (side-)effects would be if we changed it to (1).
    Josh Moore
    @joshmoore
    If I had done something "smart" (i.e. complicated) then changing the class loader could come back to bite me. Places where I could imagine this being the case is in a server like JBoss or perhaps in OSGI land a la KNIME.
    Curtis Rueden
    @ctrueden
    @hanslovsky Hmm, so which class would you try using as a starting point for SciJava/ImageJ, then? Context.class?
    Josh Moore
    @joshmoore
    @hanslovsky : gotcha. The biggest problem I can imagine with (1) would be if classes were already coming from two different class loaders. That's really the biggest gotcha: as soon as more than one class loader is in the picture, remember that two instances of class A won't necessarily be instanceof.
    Curtis Rueden
    @ctrueden
    You can try a custom ClassLoader with:
    PluginFinder pluginFinder = new DefaultPluginFinder(myOwnClassLoader);
    PluginIndex pluginIndex = new PluginIndex(pluginFinder);
    Context context = new Context(pluginIndex);
    Using the above code, you wouldn't need to hack the code of SciJava Common just to test your theory, @hanslovsky.
    Philipp Hanslovsky
    @hanslovsky

    Thanks @joshmoore and @ctrueden I will digest this a little more and try to wrap my head around it. Thanks for the pointer to the custom classloader, much less work just to confirm my theory @ctrueden

    which class would you try using as a starting point for SciJava/ImageJ, then?

    Do you mean, which class would provide the classloader? I guess I would just naively replace all occurrences of Thread.currentThread().getContextClassLoader() with MethodHandles.lookup().lookupClass().getClassLoader() but I am hesitant after reading @joshmoore's concerns.

    FWIW, (2) does solve the problem for ImageJ as well.
    I wonder how beaker notebooks get around that problem. After all, it seems to me that the scenario is very comparible to kscript
    Curtis Rueden
    @ctrueden
    Would be easy to check what the context class loader is from a BeakerX notebook.
    Philipp Hanslovsky
    @hanslovsky
    :plus1: Will do that tomorrow.
    Philipp Hanslovsky
    @hanslovsky

    I checked out the classloaders in a beakerx notebook (no other code executed).

    Kotlin:

    >>> java.lang.ClassLoader.getSystemClassLoader()
    sun.misc.Launcher$AppClassLoader@119d7047
    >>> java.lang.Thread.currentThread().contextClassLoader
    org.jetbrains.kotlin.cli.common.repl.ReplClassLoader@372b5a7c
    >>> java.lang.invoke.MethodHandles.lookup().lookupClass().classLoader
    org.jetbrains.kotlin.cli.common.repl.ReplClassLoader@560911d5

    Java:

    >>> System.out.println(java.lang.ClassLoader.getSystemClassLoader());
    sun.misc.Launcher$AppClassLoader@6ce253f1
    >>> System.out.println(java.lang.Thread.currentThread().getContextClassLoader());
    com.twosigma.beakerx.javash.JavaBeakerXUrlClassLoader@deae9b1
    >>> System.out.println(java.lang.invoke.MethodHandles.lookup().lookupClass().getClassLoader());
    com.twosigma.beakerx.javash.JavaBeakerXUrlClassLoader$JavaInternalUrlClassLoader@39d88a0
    The context class loader is not the AppClassLoader in both cases
    Philipp Hanslovsky
    @hanslovsky

    It looks like beakerx switches the class loader during evaluation:

    @Override
    public void startEvaluation() {
      classLoaderSwitcher = new ClassLoaderSwitcher(this);
      classLoaderSwitcher.start();
    }
    
    @Override
    public void endEvaluation() {
      classLoaderSwitcher.end();
    }

    and ClassLoaderSwitcher:

    package com.twosigma.beakerx;
    
    import com.twosigma.beakerx.evaluator.BaseEvaluator;
    
    public class ClassLoaderSwitcher {
    
      private ClassLoader oldld;
      private BaseEvaluator baseEvaluator;
    
      public ClassLoaderSwitcher(BaseEvaluator baseEvaluator) {
        this.baseEvaluator = baseEvaluator;
      }
    
      public void start() {
        this.oldld = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(baseEvaluator.getClassLoader());
      }
    
      public void end() {
        Thread.currentThread().setContextClassLoader(oldld);
      }
    }

    Disclaimer: This is just my intuition after a little bit of browsing of the code.

    Josh Moore
    @joshmoore
    Heh. All sounds logical though.
    Philipp Hanslovsky
    @hanslovsky
    :plus1:
    I will simply keep setting the main thread classloader at the beginning of my script, then.
    java.lang.Thread
        .currentThread()
        .setContextClassLoader(java.lang.invoke.MethodHandles.lookup().lookupClass().getClassLoader())
    Josh Moore
    @joshmoore
    If you can, I'd capture contextClassLoader and then call on end() like the other examples though.
    Philipp Hanslovsky
    @hanslovsky

    I am not sure that I can. I wrap around kscript and define a few imports and dependencies in the CUSTOM_KSCRIPT_PREAMBLE environment variable and as far as I can tell, there is no equivalent variable for post-execution. This should not be an issue, though, because this is for scripting only and the intent is to write single files for execution and not to import into other scripts.

    Thanks for help and advice @joshmoore @ctrueden

    Curtis Rueden
    @ctrueden
    @joshmoore I think the scenario is that the JVM terminates upon completion of the script, so the issue is moot. Right @hanslovsky? Or does the JVM persist afterward?
    Philipp Hanslovsky
    @hanslovsky
    In general that is correct @ctrueden. kscript has an option for interactive mode, i.e. keep the JVM running and start an interpreter, but I have not used that in practice.
    Josh Moore
    @joshmoore
    @ctrueden @hanslovsky : understood. I was thinking this was a change that would also be exposed to other scijava consumers.
    Philipp Hanslovsky
    @hanslovsky
    That was what I had in mind initially but I'll just keep it in my kscript wrapper. It's probably better that way.
    Josh Moore
    @joshmoore
    :+1:
    Curtis Rueden
    @ctrueden
    @maarzt When you get a chance, would you please edit https://imagej.net/Coding_style to add information about the new SciJava coding style CLI functionality?
    Vishesh Mangla
    @XtremeGood
    hi someone here?
    Josh Moore
    @joshmoore
    Hi @XtremeGood. Probably best if you post any questions you have to https://forum.image.sc/
    Vishesh Mangla
    @XtremeGood
    why forum?
    isnt the chat supposed to be for question-answers?
    Josh Moore
    @joshmoore
    This channel is for the development of imagej itself. If that's what you are looking to do, then go ahead and ask your question. But if you are looking for help, the forums are the place to go (and the question may already have been asked!)
    Vishesh Mangla
    @XtremeGood
    actually I wanted to detect the box in a sudoku.I have tried canny, HarrisCorners etc but none of them is working good.Is it a good place to ask about this?
    tibuch
    @tibuch
    I assume you want to apply already implemented tools and are looking for some best practice on how to analyze/extract some information from your images. In that case the forum is the right place.
    Vishesh Mangla
    @XtremeGood
    well I want to grab the main box
    tibuch
    @tibuch
    If you are programming something with imagej and have a technical question/issue regarding the programming, this would be the perfect place to ask.
    Vishesh Mangla
    @XtremeGood
    well sorry I do not use java but python but doubt is not related to programming language
    I tried open cv discussions but I couldn't get any response even after waiting for long
    Can I use yolo to detect that box?
    if yes then how?
    Curtis Rueden
    @ctrueden
    Vishesh Mangla
    @XtremeGood
    ok thanks!I will post on the forum.
    Curtis Rueden
    @ctrueden
    :+1:
    Deborah Schmidt
    @frauzufall
    Sorry I broke imagej-ui-swing master, I'll fix it..
    Deborah Schmidt
    @frauzufall
    Hi all, I am trying to figure out why the updater we uploaded today behaved differently on the Java 8 update site than on a test update site. Which made me wonder why the update procedure in imagej-ui-swing has this special behaviour for updating the updater itself.

    Copying @ctrueden's response from the private channel here:

    I believe the idea is that if there is a bug in the updater, it should patch itself, and only itself, as soon as possible before updating (and potentially destroying) anything else.
    However, I think this behavior has inflicted as many problems as it has avoided. (Impossible to measure, of course)
    Certainly, after we transitioned the updater to be built on scijava-common (a dubious decision for which I am primarily responsible), the dependency set got larger, and so that logic triggers preferential update of several core components without lock-step update of other components, which has resulted in broken installations in some instances in the past.
    The details at the time were subtle, so I don't think I can describe to you precisely why this caused problems.
    In theory, updating scijava-common (in a supposedly backwards compatible way) should not require downstream components to be updated to account for changes. But in practice, it occasionally did/does.
    I would be cautiously supportive of removing that logic, although it is difficult to say whether we'd catastrophically break anything by doing so.

    If anyone has more insights, please share! :)
    Josh Moore
    @joshmoore
    In general, I know nothing, but glancing at the original commits, there may be/have been Windows dragons, so likely slate any potential fix for additional testing on Windows (if you're not already, of course).
    Deborah Schmidt
    @frauzufall
    @joshmoore thanks for checking the commits! The note about Windows is related to the fact that you cannot swap a JAR in the background which is currently loaded from the classpath, an earlier version of this updater code snippet was doing that. So this seems nothing which should concern us now.
    The earliest commit I can find where this code appears is the initial commit of the IJ2 updater.
    No, fiji/Fiji_Updater@8133719 should be the first one, but there are also no additional notes.
    Amir El
    @AmirEl83897317_twitter
    hello, i was wondering if anyone had any ideas about how to have imagej select all pixels of a certain unit value (say unit 170 in a 8bit image), any ideas? Thanks a lot
    Josh Moore
    @joshmoore
    @AmirEl83897317_twitter : best to ask that on http://forum.image.sc
    Stephan Saalfeld
    @axtimwalde
    @AmirEl83897317_twitter threshold between 170 and 170