Esempio n. 1
0
    def finalize(self, result):
        import wx

        if self.enabled:
            from cellprofiler.utilities.jutil import kill_vm

            kill_vm()
            os._exit(0)
Esempio n. 2
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
        J.javabridge.mac_run_loop_init()
    
    # 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:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Esempio n. 3
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
        J.javabridge.mac_run_loop_init()

    # 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:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Esempio n. 4
0
 def finalize(self, result):
     try:
         import imagej.ijbridge as ijbridge
         if ijbridge.inter_proc_ij_bridge._isInstantiated():
             ijbridge.get_ij_bridge().quit()
     except:
         pass
     try:
         from cellprofiler.utilities.jutil import kill_vm
         kill_vm()
         os._exit(0)
     except:
         pass
Esempio n. 5
0
 def finalize(self, result):
     try:
         import imagej.ijbridge as ijbridge
         if ijbridge.inter_proc_ij_bridge._isInstantiated():
             ijbridge.get_ij_bridge().quit()
     except:
         pass
     try:
         from cellprofiler.utilities.jutil import kill_vm
         kill_vm()
         os._exit(0)
     except:
         pass
Esempio n. 6
0
def main():
    # XXX - move all this to a class
    
    #
    # 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
        J.javabridge.mac_run_loop_init()
    
    # 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:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Esempio n. 7
0
def main():
    # XXX - move all this to a class
    parser = optparse.OptionParser()
    parser.add_option("--work-announce",
                      dest="work_announce_address",
                      help="ZMQ port where work announcements are published",
                      default=None)
    parser.add_option("--log-level",
                      dest="log_level",
                      help="Logging level for logger: DEBUG, INFO, WARNING, ERROR",
                      default=logging.INFO)
    options, args = parser.parse_args()
    logging.root.setLevel(options.log_level)

    if not options.work_announce_address:
        parser.print_help()
        sys.exit(1)
    # Start the deadman switch thread.
    notify_started_cv = threading.Condition()
    start_daemon_thread(target=exit_on_stdin_close, 
                        name="exit_on_stdin_close",
                        args = (notify_started_cv, ))
    with notify_started_cv:
        notify_started_cv.wait()

    try:
        with AnalysisWorker(options.work_announce_address) as worker:
            worker.run()
    except CancelledException:
        logger.debug("Exiting after cancellation")
    finally:
        #
        # 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:
            J.kill_vm()
        except:
            logger.warn("Failed to stop the Java VM")
Esempio n. 8
0
 def on_close(self, evt=None):
     # Classifier needs to be told to close so it can clean up it's threads
     classifier = wx.FindWindowById(ID_CLASSIFIER) or wx.FindWindowByName('Classifier')
     if classifier and classifier.Close() == False:
         return
     if any(wx.GetApp().get_plots()):
         dlg = wx.MessageDialog(self, 'Some tools are open, are you sure you want to quit CPA?', 'Quit CellProfiler Analyst?', wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
         response = dlg.ShowModal()
         if response != wx.ID_YES:
             return
     try:
         from cellprofiler.utilities.jutil import kill_vm
         kill_vm()
     except:
         print "Failed to kill the Java VM"
     # Blow up EVVVVERYTHIIINGGG!!! Muahahahahhahahah!
     for win in wx.GetTopLevelWindows():
         logging.debug('Destroying: %s'%(win))
         win.Destroy()
     if self.tbicon is not None:
         self.tbicon.Destroy()
     self.Destroy()
Esempio n. 9
0

def get_plugin(classname):
    """Return an instance of the named plugin"""
    if classname.startswith("ij."):
        cls = J.class_for_name(classname)
    else:
        cls = J.class_for_name(classname, get_user_loader())
    cls = J.get_class_wrapper(cls, True)
    constructor = J.get_constructor_wrapper(cls.getConstructor(None))
    return constructor.newInstance(None)


if __name__ == "__main__":
    import sys

    J.attach()
    try:
        commands = get_commands()
        print "Commands: "
        for command in commands:
            print "\t" + command
        if len(sys.argv) == 2:
            execute_command(sys.argv[1])
        elif len(sys.argv) > 2:
            execute_command(sys.argv[1], sys.argv[2])

    finally:
        J.detach()
        J.kill_vm()
Esempio n. 10
0
    if len(files):
        data_files.append([path, files])
    for subdirectory in directories:
        add_jre_files(subdirectory)
    
add_jre_files("jre")
data_files += [("jre\\ext", [os.path.join(jdk_dir, "lib", "tools.jar")])]
#
# Call setup
#
try:
    setup(console=[{'script':'CellProfiler.py',
                    'icon_resources':[(1,'CellProfilerIcon.ico')]},
                   {'script':'cellprofiler\\analysis_worker.py'}],
          name='Cell Profiler',
          data_files = data_files,
          cmdclass={'msi':CellProfilerMSI
                    },
          options=opts)
finally:
    try:
        import cellprofiler.utilities.jutil as jutil
        jutil.kill_vm()
        sys.stderr.flush()
        sys.stdout.flush()
        os._exit(0)
    except:
        import traceback
        traceback.print_exc()
        print "Caught exception while killing VM"
Esempio n. 11
0
    if (delete_action.upper() == "ALL") or (delete_action.upper() == "DONE"):
        remove_if_exists(RunBatch.RunDoneFilePath(my_batch, my_run))
elif form.has_key("batch_id"):
    batch_id = int(form["batch_id"].value)
    my_batch = RunBatch.LoadBatch(batch_id)
    for my_run in my_batch["runs"]:
        if ((delete_action.upper() == "ALL") or (delete_action.upper() == "TEXT")):
            remove_if_exists(RunBatch.RunTextFilePath(my_batch, my_run))

        if (delete_action.upper() == "ALL") or (delete_action.upper() == "OUTPUT"):
            remove_if_exists(RunBatch.RunOutFilePath(my_batch, my_run))

        if (delete_action.upper() == "ALL") or (delete_action.upper() == "DONE"):
            remove_if_exists(RunBatch.RunDoneFilePath(my_batch, my_run))
    
    
url = "ViewBatch.py?batch_id=%(batch_id)d"%(my_batch)
print "Content-Type: text/html"
print
print "<html><head>"
print "<meta http-equiv='refresh' content='0; URL=%(url)s' />"%(globals())
print "</head>"
print "<body>This page should be redirected to <a href='%(url)s'/>%(url)s</a></body>"%(globals())
print "</html>"
try:
    import cellprofiler.utilities.jutil as jutil
    jutil.kill_vm()
except:
    import traceback
    traceback.print_exc()
Esempio n. 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 cellprofiler.utilities.jutil 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>])
         where <output-file> is the optional filename for the output file of 
               measurements when running headless. 
         The flags -p, -r and -c are required for a headless run."""
    
    parser = optparse.OptionParser(usage=usage)
    parser.add_option("-p", "--pipeline", "--project",
                      dest="pipeline_filename",
Esempio n. 13
0
                         "()Ljava/lang/ClassLoader;")


def get_plugin(classname):
    '''Return an instance of the named plugin'''
    if classname.startswith("ij."):
        cls = J.class_for_name(classname)
    else:
        cls = J.class_for_name(classname, get_user_loader())
    cls = J.get_class_wrapper(cls, True)
    constructor = J.get_constructor_wrapper(cls.getConstructor(None))
    return constructor.newInstance(None)


if __name__ == "__main__":
    import sys
    J.attach()
    try:
        commands = get_commands()
        print "Commands: "
        for command in commands:
            print "\t" + command
        if len(sys.argv) == 2:
            execute_command(sys.argv[1])
        elif len(sys.argv) > 2:
            execute_command(sys.argv[1], sys.argv[2])

    finally:
        J.detach()
        J.kill_vm()
Esempio n. 14
0
 def finalize(self, result):
     import wx
     if self.enabled:
         from cellprofiler.utilities.jutil import kill_vm
         kill_vm()
         os._exit(0)
Esempio n. 15
0
def main():
    # XXX - move all this to a class
    parser = optparse.OptionParser()
    parser.add_option("--work-announce",
                      dest="work_announce_address",
                      help="ZMQ port where work announcements are published",
                      default=None)
    parser.add_option("--log-level",
                      dest="log_level",
                      help="Logging level for logger: DEBUG, INFO, WARNING, ERROR",
                      default=logging.INFO)
    options, args = parser.parse_args()
    logging.root.setLevel(options.log_level)

    if not options.work_announce_address:
        parser.print_help()
        sys.exit(1)
    #
    # 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
        J.javabridge.mac_run_loop_init()
     
    # 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(options.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:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")
Esempio n. 16
0
def main():
    # XXX - move all this to a class
    parser = optparse.OptionParser()
    parser.add_option("--work-announce",
                      dest="work_announce_address",
                      help="ZMQ port where work announcements are published",
                      default=None)
    parser.add_option(
        "--log-level",
        dest="log_level",
        help="Logging level for logger: DEBUG, INFO, WARNING, ERROR",
        default=logging.INFO)
    options, args = parser.parse_args()
    logging.root.setLevel(options.log_level)

    if not options.work_announce_address:
        parser.print_help()
        sys.exit(1)
    #
    # 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
        J.javabridge.mac_run_loop_init()

    # 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(options.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:
        J.kill_vm()
    except:
        logger.warn("Failed to stop the Java VM")