Sfoglia il codice sorgente

implement system values background_timeout and verbose_error_level

implement correct error level handling based on verbose_error_level ,  fix  double print of  tcl error and  do not wrap unknown  exceptions into TCL known
Kamil Sopko 9 anni fa
parent
commit
e236a60be9
2 ha cambiato i file con 23 aggiunte e 17 eliminazioni
  1. 19 8
      FlatCAMApp.py
  2. 4 9
      tclCommands/TclCommand.py

+ 19 - 8
FlatCAMApp.py

@@ -286,6 +286,8 @@ class App(QtCore.QObject):
             "cncjob_tooldia": 0.016,
             "cncjob_tooldia": 0.016,
             "cncjob_prepend": "",
             "cncjob_prepend": "",
             "cncjob_append": "",
             "cncjob_append": "",
+            "background_timeout": 300000, #default value is 5 minutes
+            "verbose_error_level": 0, # shell verbosity 0 = default(python trace only for unknown errors), 1 = show trace(show trace allways), 2 = (For the future).
 
 
             # Persistence
             # Persistence
             "last_folder": None,
             "last_folder": None,
@@ -679,7 +681,6 @@ class App(QtCore.QObject):
         """
         """
         this exception is deffined here, to be able catch it if we sucessfully handle all errors from shell command
         this exception is deffined here, to be able catch it if we sucessfully handle all errors from shell command
         """
         """
-
         pass
         pass
 
 
     def raise_tcl_unknown_error(self, unknownException):
     def raise_tcl_unknown_error(self, unknownException):
@@ -704,14 +705,24 @@ class App(QtCore.QObject):
         """
         """
 
 
         if isinstance(error, Exception):
         if isinstance(error, Exception):
+
             exc_type, exc_value, exc_traceback = error_info
             exc_type, exc_value, exc_traceback = error_info
-            trc=traceback.format_list(traceback.extract_tb(exc_traceback))
-            trc_formated=[]
-            for a in reversed(trc):
-                trc_formated.append(a.replace("    ", " > ").replace("\n",""))
-            text="%s\nPython traceback: %s\n%s" % (exc_value,
-                             exc_type,
-                             "\n".join(trc_formated))
+            if not isinstance(error, self.TclErrorException):
+                show_trace = 1
+            else:
+                show_trace = int(self.defaults['verbose_error_level'])
+
+            if show_trace > 0:
+                trc=traceback.format_list(traceback.extract_tb(exc_traceback))
+                trc_formated=[]
+                for a in reversed(trc):
+                    trc_formated.append(a.replace("    ", " > ").replace("\n",""))
+                text="%s\nPython traceback: %s\n%s" % (exc_value,
+                                 exc_type,
+                                 "\n".join(trc_formated))
+
+            else:
+                text="%s" % error
         else:
         else:
             text=error
             text=error
 
 

+ 4 - 9
tclCommands/TclCommand.py

@@ -291,9 +291,6 @@ class TclCommandSignaled(TclCommand):
         it handles  all neccessary stuff about blocking and passing exeptions
         it handles  all neccessary stuff about blocking and passing exeptions
     """
     """
 
 
-    # default  timeout for operation is  300000 sec, but it can be much more
-    default_timeout = 300000
-
     output = None
     output = None
 
 
     def execute_call(self, args, unnamed_args):
     def execute_call(self, args, unnamed_args):
@@ -320,7 +317,7 @@ class TclCommandSignaled(TclCommand):
         """
         """
 
 
         @contextmanager
         @contextmanager
-        def wait_signal(signal, timeout=10000):
+        def wait_signal(signal, timeout=300000):
             """Block loop until signal emitted, or timeout (ms) elapses."""
             """Block loop until signal emitted, or timeout (ms) elapses."""
             loop = QtCore.QEventLoop()
             loop = QtCore.QEventLoop()
 
 
@@ -357,10 +354,10 @@ class TclCommandSignaled(TclCommand):
             # Restore exception management
             # Restore exception management
             sys.excepthook = oeh
             sys.excepthook = oeh
             if ex:
             if ex:
-                self.raise_tcl_error(str(ex[0]))
+                raise ex[0]
 
 
             if status['timed_out']:
             if status['timed_out']:
-                self.app.raise_tcl_unknown_error('Operation timed out!')
+                self.app.raise_tcl_unknown_error("Operation timed outed! Consider increasing option '-timeout <miliseconds>' for command or 'set_sys background_timeout <miliseconds>'.")
 
 
         try:
         try:
             self.log.debug("TCL command '%s' executed." % str(self.__class__))
             self.log.debug("TCL command '%s' executed." % str(self.__class__))
@@ -370,7 +367,7 @@ class TclCommandSignaled(TclCommand):
                 passed_timeout=args['timeout']
                 passed_timeout=args['timeout']
                 del args['timeout']
                 del args['timeout']
             else:
             else:
-                passed_timeout=self.default_timeout
+                passed_timeout= self.app.defaults['background_timeout']
 
 
             # set detail for processing, it will be there until next open or close
             # set detail for processing, it will be there until next open or close
             self.app.shell.open_proccessing(self.get_current_command())
             self.app.shell.open_proccessing(self.get_current_command())
@@ -378,8 +375,6 @@ class TclCommandSignaled(TclCommand):
             def handle_finished(obj):
             def handle_finished(obj):
                 self.app.shell_command_finished.disconnect(handle_finished)
                 self.app.shell_command_finished.disconnect(handle_finished)
                 if self.error is not None:
                 if self.error is not None:
-                    self.log.error("TCL command '%s' failed." % str(self))
-                    self.app.display_tcl_error(self.error, self.error_info)
                     self.raise_tcl_unknown_error(self.error)
                     self.raise_tcl_unknown_error(self.error)
 
 
             self.app.shell_command_finished.connect(handle_finished)
             self.app.shell_command_finished.connect(handle_finished)