def OnExit(self):
     from imagej.imagej2 import allow_quit
     allow_quit()
     from javabridge import deactivate_awt
     deactivate_awt()
     # restore previous exception hook
     sys.excepthook = self.orig_excepthook
 def OnExit(self):
     from imagej.imagej2 import allow_quit
     allow_quit()
     from javabridge import deactivate_awt
     deactivate_awt()
     # restore previous exception hook
     sys.excepthook = self.orig_excepthook
 def OnExit(self):
     from imagej.imagej2 import allow_quit
     allow_quit()
     from cellprofiler.utilities.jutil import deactivate_awt
     deactivate_awt()
     # restore previous exception hook
     sys.excepthook = self.orig_excepthook
Example #4
0
def cp_stop_vm(kill=True):
    '''Shut down the Java VM

    Check for headlessness and the state of ImageJ and take
    whatever action is needed to stop AWT and the JVM.
    '''
    from imagej.imagej2 import allow_quit, the_imagej_context

    try:
        ij1 = javabridge.JClassWrapper("ij.IJ").getInstance()
    except javabridge.JavaException as e:
        logger.debug("No available instance: %s" % str(e))
        ij1 = None

    if the_imagej_context is not None:
        #
        # Tell the app service that it's OK to quit without prompt
        #
        allow_quit()
        javabridge.call(the_imagej_context.getContext(), "dispose", "()V")
    if ij1 is not None:
        #
        # Yes, the proper way to get ImageJ to quit is
        # to start it.
        #
        ij1.run()
    if kill:
        javabridge.kill_vm()
Example #5
0
def cp_stop_vm(kill=True):
    '''Shut down the Java VM

    Check for headlessness and the state of ImageJ and take
    whatever action is needed to stop AWT and the JVM.
    '''
    from imagej.imagej2 import allow_quit, the_imagej_context

    try:
        ij1 = javabridge.JClassWrapper("ij.IJ").getInstance()
    except javabridge.JavaException as e:
        logger.debug("No available instance: %s" % str(e))
        ij1 = None

    if the_imagej_context is not None:
        #
        # Tell the app service that it's OK to quit without prompt
        #
        allow_quit()
        javabridge.call(the_imagej_context.getContext(), "dispose", "()V")
    if ij1 is not None:
        #
        # Yes, the proper way to get ImageJ to quit is
        # to start it.
        #
        ij1.run()
    if kill:
        javabridge.kill_vm()
Example #6
0
 def OnExit(self):
     from imagej.imagej2 import allow_quit
     allow_quit()
     from cellprofiler.utilities.jutil import deactivate_awt
     deactivate_awt()
     # restore previous exception hook
     sys.excepthook = self.orig_excepthook
def main():
    #
    # For Windows build with Ilastik, look for site-packages
    # in order to find Ilastik sources.
    #
    if hasattr(sys, 'frozen') and sys.platform == "win32":
        root = os.path.split(sys.argv[0])[0]
        if len(root) == 0:
            root = os.curdir
        root = os.path.abspath(root)
        site_packages = os.path.join(root, 'site-packages').encode('utf-8')
        if os.path.exists(site_packages) and os.path.isdir(site_packages):
            import site
            site.addsitedir(site_packages)
    #
    # For OS/X set up the UI elements that users expect from
    # an app.
    #
    if sys.platform == "darwin":
        from cellprofiler.icons import get_builtin_images_path
        
        icon_path = os.path.join(get_builtin_images_path(), "CellProfilerIcon.png")
        os.environ["APP_NAME_%d" % os.getpid()] = "CellProfilerWorker"
        os.environ["APP_ICON_%d" % os.getpid()] = icon_path
    
    # Start the JVM
    from cellprofiler.utilities.cpjvm import cp_start_vm
    cp_start_vm()
    
    deadman_start_socket = the_zmq_context.socket(zmq.PAIR)
    deadman_start_socket.bind(DEADMAN_START_ADDR)
    
    # Start the deadman switch thread.
    start_daemon_thread(target=exit_on_stdin_close, 
                        name="exit_on_stdin_close")
    deadman_start_socket.recv()
    deadman_start_socket.close()
    
    from cellprofiler.knime_bridge import KnimeBridgeServer
    with AnalysisWorker(work_announce_address) as worker:
        worker_thread = threading.Thread(target = worker.run, 
                                         name="WorkerThread")
        worker_thread.setDaemon(True)
        worker_thread.start()
        with KnimeBridgeServer(the_zmq_context,
                               knime_bridge_address,
                               NOTIFY_ADDR, NOTIFY_STOP):
            enter_run_loop()
            worker_thread.join()
            
    #
    # Shutdown - need to handle some global cleanup here
    #
    try:
        from ilastik.core.jobMachine import GLOBAL_WM
        GLOBAL_WM.stopWorkers()
    except:
        logger.warn("Failed to stop Ilastik")
    try:
        from imagej.imagej2 import allow_quit
        allow_quit()
    except:
        logger.warn("Failed to signal ImageJ to stop")
    try:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
def main():
    #
    # For Windows build with Ilastik, look for site-packages
    # in order to find Ilastik sources.
    #
    if hasattr(sys, 'frozen') and sys.platform == "win32":
        root = os.path.split(sys.argv[0])[0]
        if len(root) == 0:
            root = os.curdir
        root = os.path.abspath(root)
        site_packages = os.path.join(root, 'site-packages').encode('utf-8')
        if os.path.exists(site_packages) and os.path.isdir(site_packages):
            import site
            site.addsitedir(site_packages)
    #
    # For OS/X set up the UI elements that users expect from
    # an app.
    #
    if sys.platform == "darwin":
        from cellprofiler.icons import get_builtin_images_path
        
        icon_path = os.path.join(get_builtin_images_path(), "CellProfilerIcon.png")
        os.environ["APP_NAME_%d" % os.getpid()] = "CellProfilerWorker"
        os.environ["APP_ICON_%d" % os.getpid()] = icon_path
    
    # Importing bioformats starts the JVM
    import bioformats
    # Start the deadman switch thread.
    start_daemon_thread(target=exit_on_stdin_close, 
                        name="exit_on_stdin_close")
    with stdin_monitor_lock:
        while not stdin_monitor_started:
            stdin_monitor_cv.wait()
        
    with AnalysisWorker(work_announce_address) as worker:
        worker_thread = threading.Thread(target = worker.run, 
                                         name="WorkerThread")
        worker_thread.setDaemon(True)
        worker_thread.start()
        print "Entering run loop"
        enter_run_loop()
        print "Exiting run loop"
        worker_thread.join()
            
    #
    # Shutdown - need to handle some global cleanup here
    #
    try:
        from ilastik.core.jobMachine import GLOBAL_WM
        GLOBAL_WM.stopWorkers()
    except:
        logger.warn("Failed to stop Ilastik")
    try:
        from imagej.imagej2 import allow_quit
        allow_quit()
    except:
        logger.warn("Failed to signal ImageJ to stop")
    try:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Example #9
0
def main():
    #
    # For Windows build with Ilastik, look for site-packages
    # in order to find Ilastik sources.
    #
    if hasattr(sys, 'frozen') and sys.platform == "win32":
        root = os.path.split(sys.argv[0])[0]
        if len(root) == 0:
            root = os.curdir
        root = os.path.abspath(root)
        site_packages = os.path.join(root, 'site-packages').encode('utf-8')
        if os.path.exists(site_packages) and os.path.isdir(site_packages):
            import site
            site.addsitedir(site_packages)
    #
    # For OS/X set up the UI elements that users expect from
    # an app.
    #
    if sys.platform == "darwin":
        from cellprofiler.icons import get_builtin_images_path
        
        icon_path = os.path.join(get_builtin_images_path(), "CellProfilerIcon.png")
        os.environ["APP_NAME_%d" % os.getpid()] = "CellProfilerWorker"
        os.environ["APP_ICON_%d" % os.getpid()] = icon_path
    
    # Start the JVM
    from cellprofiler.utilities.cpjvm import cp_start_vm
    cp_start_vm()
    
    deadman_start_socket = the_zmq_context.socket(zmq.PAIR)
    deadman_start_socket.bind(DEADMAN_START_ADDR)
    
    # Start the deadman switch thread.
    start_daemon_thread(target=exit_on_stdin_close, 
                        name="exit_on_stdin_close")
    deadman_start_socket.recv()
    deadman_start_socket.close()
    # Limit Ilastik to one job thread.
    try:
        from ilastik.core.jobMachine import GLOBAL_WM
        GLOBAL_WM.set_thread_count(1)
    except:
        pass
    
    from cellprofiler.knime_bridge import KnimeBridgeServer
    with AnalysisWorker(work_announce_address) as worker:
        worker_thread = threading.Thread(target = worker.run, 
                                         name="WorkerThread")
        worker_thread.setDaemon(True)
        worker_thread.start()
        with KnimeBridgeServer(the_zmq_context,
                               knime_bridge_address,
                               NOTIFY_ADDR, NOTIFY_STOP):
            enter_run_loop()
            worker_thread.join()
            
    #
    # Shutdown - need to handle some global cleanup here
    #
    try:
        from ilastik.core.jobMachine import GLOBAL_WM
        GLOBAL_WM.stopWorkers()
    except:
        logger.warn("Failed to stop Ilastik")
    try:
        from imagej.imagej2 import allow_quit
        allow_quit()
    except:
        logger.warn("Failed to signal ImageJ to stop")
    try:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Example #10
0
def cp_stop_vm(kill=True):
    '''Shut down the Java VM

    Check for headlessness and the state of ImageJ and take
    whatever action is needed to stop AWT and the JVM.
    '''
    if not cpprefs.get_awt_headless():
        from imagej.imagej2 import allow_quit, the_imagej_context
        ij1 = javabridge.JClassWrapper("ij.IJ").getInstance()
        if ij1 is not None and ij1.isVisible():
            #
            # If legacy ImageJ is visible, then we have
            # to pick it apart in order to get around
            # the "Fiji won't quit" bug:
            #
            # http://fiji.sc/2014-07-11_-_Fiji_won%27t_quit!
            # http://fiji.sc/bugzilla/show_bug.cgi?id=805
            # https://github.com/fiji/fiji/issues/94
            # https://bugs.openjdk.java.net/browse/JDK-8061307
            #
            # The following code was needed in order to get around
            # the JDK problem on Red Hat 6 OpenJDK 1.7.0_79
            #
            env = javabridge.get_env()
            #
            # Use the window manager to find all of the ImagePlus windows.
            # Tell them that it's OK to close w/o prompt.
            # Close them all.
            #
            wm = javabridge.JClassWrapper("ij.WindowManager")
            for i in range(1, wm.getImageCount()+1):
                wm.getImage(i).changes = False
            wm.closeAllWindows()
            #
            # Pick apart and destroy IJ1's menus
            #
            menubar = ij1.getMenuBar()
            if menubar is not None:
                while menubar.getMenuCount() > 0:
                    menubar.remove(menubar.getMenu(0))
            #
            # Mercilessly pick apart all other windows
            # This throws the exception described in JDK-8061307
            #
            try:
                ij1.removeAll()
            except:
                logger.info("Caught expected AWT exception", exc_info=1)
        if the_imagej_context is not None:
            #
            # Tell the app service that it's OK to quit without prompt
            #
            allow_quit()
            app = javabridge.JWrapper(the_imagej_context.getService(
                    "org.scijava.app.AppService")).getApp()
            app.quit()
        if ij1 is not None:
            #
            # Yes, the proper way to get ImageJ to quit is
            # to start it.
            #
            ij1.run()
        #
        # Account for a "bug" in javabridge.1.0.11 that doesn't shelter
        # the caller of deactivate_awt() from the OpenJDK bug.
        #
        if javabridge.__version__ < "1.0.12":
            javabridge.jutil.CLOSE_ALL_WINDOWS = """
                new java.lang.Runnable() {
                    run: function() {
                        var all_frames = java.awt.Frame.getFrames();
                        if (all_frames) {
                            for (idx in all_frames) {
                                try {
                                    all_frames[idx].dispose();
                                } catch (err) {
                                }
                            }
                        }
                    }
               }"""
        javabridge.jutil.deactivate_awt()
    if kill:
        javabridge.kill_vm()
 def OnExit(self):
     from imagej.imagej2 import allow_quit
     allow_quit()
     # restore previous exception hook
     sys.excepthook = self.orig_excepthook
Example #12
0
    
    finally:
        if __name__ == "__main__":
            try:
                from ilastik.core.jobMachine import GLOBAL_WM
                GLOBAL_WM.stopWorkers()
            except:
                logging.root.warn("Failed to stop Ilastik")
            try:
                from cellprofiler.utilities.zmqrequest import join_to_the_boundary
                join_to_the_boundary()
            except:
                logging.root.warn("Failed to stop zmq boundary")
            try:
                from imagej.imagej2 import allow_quit, quit
                allow_quit()
                quit()
                    
            except:
                logging.root.warn("Failed to dispose of ImageJ")
            try:
                from javabridge import kill_vm
                kill_vm()
            except:
                logging.root.warn("Failed to stop the JVM")
            os._exit(0)

def parse_args(args):
    '''Parse the CellProfiler command-line arguments'''
    import optparse
    usage = """usage: %prog [options] [<output-file>])
Example #13
0
    finally:
        if __name__ == "__main__":
            try:
                from ilastik.core.jobMachine import GLOBAL_WM
                GLOBAL_WM.stopWorkers()
            except:
                logging.root.warn("Failed to stop Ilastik")
            try:
                from cellprofiler.utilities.zmqrequest import join_to_the_boundary
                join_to_the_boundary()
            except:
                logging.root.warn("Failed to stop zmq boundary")
            try:
                from imagej.imagej2 import allow_quit, quit
                allow_quit()
                quit()

            except:
                logging.root.warn("Failed to dispose of ImageJ")
            try:
                from javabridge import kill_vm
                kill_vm()
            except:
                logging.root.warn("Failed to stop the JVM")
            os._exit(0)


def parse_args(args):
    '''Parse the CellProfiler command-line arguments'''
    import optparse
def main():
    #
    # For Windows build with Ilastik, look for site-packages
    # in order to find Ilastik sources.
    #
    if hasattr(sys, 'frozen') and sys.platform == "win32":
        root = os.path.split(sys.argv[0])[0]
        if len(root) == 0:
            root = os.curdir
        root = os.path.abspath(root)
        site_packages = os.path.join(root, 'site-packages').encode('utf-8')
        if os.path.exists(site_packages) and os.path.isdir(site_packages):
            import site
            site.addsitedir(site_packages)
    #
    # For OS/X set up the UI elements that users expect from
    # an app.
    #
    if sys.platform == "darwin":
        from cellprofiler.icons import get_builtin_images_path
        
        icon_path = os.path.join(get_builtin_images_path(), "CellProfilerIcon.png")
        os.environ["APP_NAME_%d" % os.getpid()] = "CellProfilerWorker"
        os.environ["APP_ICON_%d" % os.getpid()] = icon_path
    
    # Importing bioformats starts the JVM
    import bioformats
    # Start the deadman switch thread.
    start_daemon_thread(target=exit_on_stdin_close, 
                        name="exit_on_stdin_close")
    with stdin_monitor_lock:
        while not stdin_monitor_started:
            stdin_monitor_cv.wait()
        
    with AnalysisWorker(work_announce_address) as worker:
        worker_thread = threading.Thread(target = worker.run, 
                                         name="WorkerThread")
        worker_thread.setDaemon(True)
        worker_thread.start()
        print "Entering run loop"
        enter_run_loop()
        print "Exiting run loop"
        worker_thread.join()
            
    #
    # Shutdown - need to handle some global cleanup here
    #
    try:
        from ilastik.core.jobMachine import GLOBAL_WM
        GLOBAL_WM.stopWorkers()
    except:
        logger.warn("Failed to stop Ilastik")
    try:
        from imagej.imagej2 import allow_quit
        allow_quit()
    except:
        logger.warn("Failed to signal ImageJ to stop")
    try:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Example #15
0
 def OnExit(self):
     from imagej.imagej2 import allow_quit
     allow_quit()
     # restore previous exception hook
     sys.excepthook = self.orig_excepthook