コード例 #1
0
 def test_run_plugin_exceptions(self):
     """Verify run_plugin returns exception messages in Queue"""
     plugin_data = np.zeros(5) # Use division by zero exception in NormalizePlugin
     plugin_config = {'pi': 3.141592654}
     plugin_cls = self.get_normalize_plugin()
     plugin_process, plugin_queue, exception_queue = model.run_plugin(plugin_cls,
                                                                      data=plugin_data, config=plugin_config)
     exc_type, exc = exception_queue.get(block=True)
     self.assertTrue(isinstance(exc, Exception))
コード例 #2
0
 def test_run_plugin(self):
     """Verify the main model can run a loaded plugin"""
     plugin_data = np.array(self.random_data())
     plugin_config = {'pi': 3.141592654}
     plugin_cls = self.get_normalize_plugin()
     plugin_process, plugin_queue, exception_queue = model.run_plugin(plugin_cls,
                                                                      data=plugin_data, config=plugin_config)
     self.assertTrue(isinstance(plugin_process, multiprocessing.Process))
     returned_data = plugin_queue.get()
     expected_data = plugin_data / np.max(plugin_data)
     self.assertTrue(np.array_equal(expected_data, returned_data))
コード例 #3
0
 def run_plugin(self, plugin_cls, **kwargs):
     """Runs plugin of specified class plugin_cls on current data set,
     replaces current data and refreshes plot"""
     cfg = None
     # Instantiate the plugin to see if it has a self.config dict
     # that should be configured by the user prior to execution
     plugin_instance = plugin_cls()
     if hasattr(plugin_instance, "config"):
         cfg = self.configure_plugin_dlg(plugin_instance)
         if cfg is None:
             return
     try:
         plugin_process, plugin_queue, exception_queue = mainmodel.run_plugin(plugin_cls, self.data, cfg, **kwargs)
     except MemoryError as err: # Insufficient memory to run plugin with current data
         err_dlg = wx.MessageDialog(self.view, message="Insufficient memory to run plugin.",
                                    caption="Unable To Run Plugin",
                                    style=wx.ICON_ERROR)
         err_dlg.ShowModal()
         err_dlg.Destroy()
         return
     keepGoing = True
     try:
         progress_dlg = wx.ProgressDialog("Running Plugin",
                                          "Please wait, executing plugin...",
                                          parent=self.view,
                                          style=wx.PD_CAN_ABORT)
         while keepGoing:
             wx.MilliSleep(125)
             (keepGoing, skip) = progress_dlg.UpdatePulse()
             try:
                 if not plugin_process.is_alive():
                     # Catch low-level exceptions thrown by multiprocessing, such as MemoryError
                     # exceptions raised when attempting to send data through the queue
                     module_logger.error("Unknown error occurred during plugin execution, plugin terminated")
                     err_msg = ' '.join(["An unknown error has occurred running the plugin.",
                                         "Please ensure your system has sufficient memory and disk space to process this data.",
                                         "If the problem persists, please contact the plugin's author."])
                     err_dlg = wx.MessageDialog(self.view, message=err_msg,
                                                caption="Unable To Run Plugin",
                                                style=wx.ICON_ERROR)
                     err_dlg.ShowModal()
                     err_dlg.Destroy()
                     break
                 exc_type, exc = exception_queue.get(block=False)
                 err_str = str(exc)
                 if len(err_str) == 0:
                     err_str = exc_type.__name__
                 module_logger.error("Error occurred running plugin: {0}".format(err_str))
                 err_msg = "An error occurred while running the plugin:\n{0}".format(err_str)
                 err_dlg = wx.MessageDialog(self.view, message=err_msg,
                                            caption="Unable To Run Plugin",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
                 err_dlg.Destroy()
                 break
             except Queue.Empty:
                 pass
             try:
                 returned_data = plugin_queue.get(False)
             except Queue.Empty:
                 continue
             if returned_data is not None:
                 self.model.data = returned_data
                 break
             if not keepGoing:
                 break
             wx.getApp().Yield()
     finally:
         plugin_process.join()
         progress_dlg.Destroy()
コード例 #4
0
 def run_plugin(self, plugin_cls, **kwargs):
     """Runs plugin of specified class plugin_cls on current data set,
     replaces current data and refreshes plot"""
     cfg = None
     # Instantiate the plugin to see if it has a self.config dict
     # that should be configured by the user prior to execution
     plugin_instance = plugin_cls()
     if hasattr(plugin_instance, "config"):
         cfg = self.configure_plugin_dlg(plugin_instance)
         if cfg is None:
             return
     try:
         plugin_process, plugin_queue, exception_queue = mainmodel.run_plugin(
             plugin_cls, self.data, cfg, **kwargs)
     except MemoryError as err:  # Insufficient memory to run plugin with current data
         err_dlg = wx.MessageDialog(
             self.view,
             message="Insufficient memory to run plugin.",
             caption="Unable To Run Plugin",
             style=wx.ICON_ERROR)
         err_dlg.ShowModal()
         err_dlg.Destroy()
         return
     keepGoing = True
     try:
         progress_dlg = wx.ProgressDialog(
             "Running Plugin",
             "Please wait, executing plugin...",
             parent=self.view,
             style=wx.PD_CAN_ABORT)
         while keepGoing:
             wx.MilliSleep(125)
             (keepGoing, skip) = progress_dlg.UpdatePulse()
             try:
                 if not plugin_process.is_alive():
                     # Catch low-level exceptions thrown by multiprocessing, such as MemoryError
                     # exceptions raised when attempting to send data through the queue
                     module_logger.error(
                         "Unknown error occurred during plugin execution, plugin terminated"
                     )
                     err_msg = ' '.join([
                         "An unknown error has occurred running the plugin.",
                         "Please ensure your system has sufficient memory and disk space to process this data.",
                         "If the problem persists, please contact the plugin's author."
                     ])
                     err_dlg = wx.MessageDialog(
                         self.view,
                         message=err_msg,
                         caption="Unable To Run Plugin",
                         style=wx.ICON_ERROR)
                     err_dlg.ShowModal()
                     err_dlg.Destroy()
                     break
                 exc_type, exc = exception_queue.get(block=False)
                 err_str = str(exc)
                 if len(err_str) == 0:
                     err_str = exc_type.__name__
                 module_logger.error(
                     "Error occurred running plugin: {0}".format(err_str))
                 err_msg = "An error occurred while running the plugin:\n{0}".format(
                     err_str)
                 err_dlg = wx.MessageDialog(self.view,
                                            message=err_msg,
                                            caption="Unable To Run Plugin",
                                            style=wx.ICON_ERROR)
                 err_dlg.ShowModal()
                 err_dlg.Destroy()
                 break
             except Queue.Empty:
                 pass
             try:
                 returned_data = plugin_queue.get(False)
             except Queue.Empty:
                 continue
             if returned_data is not None:
                 self.model.data = returned_data
                 break
             if not keepGoing:
                 break
             wx.getApp().Yield()
     finally:
         plugin_process.join()
         progress_dlg.Destroy()