Better detection of KeyboardInterrupts. (Christoph Wiedemann)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 21 Oct 2003 12:18:38 +0000 (12:18 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 21 Oct 2003 12:18:38 +0000 (12:18 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@826 fdb21ef1-2011-0410-befe-b5e4ea1792b1

19 files changed:
src/CHANGES.txt
src/engine/SCons/Action.py
src/engine/SCons/Job.py
src/engine/SCons/Node/FS.py
src/engine/SCons/Options.py
src/engine/SCons/Platform/win32.py
src/engine/SCons/SConf.py
src/engine/SCons/Script/SConscript.py
src/engine/SCons/Script/__init__.py
src/engine/SCons/Sig/__init__.py
src/engine/SCons/Taskmaster.py
src/engine/SCons/Tool/hpc++.py
src/engine/SCons/Tool/hplink.py
src/engine/SCons/Tool/javah.py
src/engine/SCons/Tool/msvc.py
src/engine/SCons/Tool/msvs.py
src/engine/SCons/Tool/rmic.py
src/engine/SCons/Tool/sunlink.py
src/engine/SCons/Util.py

index b7793236dceb299fc08f37b4f603ccbad011f322..bb32ad8baf744c6b4948572ea1114d003b6126c3 100644 (file)
@@ -175,6 +175,9 @@ RELEASE X.XX - XXX
 
   - Support calling a Builder when a Configure context is still open.
 
+  - Handle interrupts better by eliminating all try:-except: blocks
+    which caught any and all exceptions, including KeyboardInterrupt.
+
 
 
 RELEASE 0.92 - Wed, 20 Aug 2003 03:45:28 -0500
index 633bb064eefab23707a3e1979645c0b2ffbbda14..13409aa314152fae9f40a67b6ce70dc10a1ab987 100644 (file)
@@ -388,7 +388,7 @@ class FunctionAction(ActionBase):
         try:
             # "self.execfunction" is a function.
             code = self.execfunction.func_code.co_code
-        except:
+        except AttributeError:
             # "self.execfunction" is a callable object.
             code = self.execfunction.__call__.im_func.func_code.co_code
         return str(code) + env.subst(string.join(map(lambda v: '${'+v+'}',
index b5296dc824ca0ec2978b6cd343fcd6fa0f6475d8..d26b73cad5b2f6e39b4c2854a1769b046a186c99 100644 (file)
@@ -135,6 +135,9 @@ class Worker(threading.Thread):
 
             try:
                 task.execute()
+            except KeyboardInterrupt:
+                # be explicit here for test/interrupts.py
+                ok = False
             except:
                 ok = 0
             else:
index b183a8812a8e8dd48fece894994fe0a72d0a1e3c..cffa2b5dbf8f0ed4cf8e3a97a13491860ffd4987 100644 (file)
@@ -721,7 +721,7 @@ class FS:
                 self._cwd = dir
                 if change_os_dir:
                     os.chdir(dir.abspath)
-        except:
+        except OSError:
             self._cwd = curr
             raise
 
@@ -1476,7 +1476,7 @@ class File(Base):
     def rfile(self):
         try:
             return self._rfile
-        except:
+        except AttributeError:
             self._rfile = self
             if not self.exists():
                 n = self.fs.Rsearch(self.path, clazz=File,
index 45f607f425f39f071e2ce419dc8b7247a5921a54..f4d2bcc2946bceada7494626554013c2ddda79d6 100644 (file)
@@ -163,6 +163,8 @@ class Options:
                         value = env[option.key]
                         try:
                             eval(repr(value))
+                        except KeyboardInterrupt:
+                            raise
                         except:
                             # Convert stuff that has a repr() that
                             # cannot be evaluated into a string
index 08fb296693cf846d7b78632753cea95705d1418e..c5900550361b72a5c58040e66808cc31a7586cfe 100644 (file)
@@ -166,15 +166,15 @@ def piped_spawn(sh, escape, cmd, args, env, stdout, stderr):
             try:
                 stdout.write(open( tmpFileStdout, "r" ).read())
                 os.remove( tmpFileStdout )
-            except:
+            except (IOError, OSError):
                 pass
 
         if stderr != None and stderrRedirected == 0:
             try:
                 stderr.write(open( tmpFileStderr, "r" ).read())
                 os.remove( tmpFileStderr )
-            except:
-                    pass
+            except (IOError, OSError):
+                pass
         return ret
 
 def spawn(sh, escape, cmd, args, env):
@@ -199,7 +199,7 @@ def get_system_root():
     # A resonable default if we can't read the registry
     try:
         val = os.environ['SYSTEMROOT']
-    except:
+    except KeyError:
         val = "C:/WINDOWS"
         pass
 
@@ -216,6 +216,8 @@ def get_system_root():
                 k=SCons.Util.RegOpenKeyEx(SCons.Util.hkey_mod.HKEY_LOCAL_MACHINE,
                                           'Software\\Microsoft\\Windows\\CurrentVersion')
                 val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
+            except KeyboardInterrupt:
+                raise
             except:
                 pass
     return val
@@ -260,6 +262,8 @@ def generate(env):
                                               'Software\\Microsoft\\Windows\\CurrentVersion')
                 val, tok = SCons.Util.RegQueryValueEx(k, 'SystemRoot')
                 cmd_interp = os.path.join(val, 'command.com')
+            except KeyboardInterrupt:
+                raise
             except:
                 pass
 
index 144099f896e73a4392f0e30f40759eef345efc43..04955a4fa3dce176209bdbb608284584f1c49fb1 100644 (file)
@@ -219,8 +219,6 @@ class SConf:
                 sys.stderr.write("scons: *** [%s] %s\n" % (e.node, e.errstr))
                 if e.errstr == 'Exception':
                     traceback.print_exception(e.args[0], e.args[1], e.args[2])
-            except:
-                raise
 
             for n in nodes:
                 state = n.get_state()
@@ -401,6 +399,8 @@ class SConf:
             if cacheDesc['scons_version'] != SCons.__version__:
                 raise Exception, "version mismatch"
             self.cache = cacheDesc['data']
+        except KeyboardInterrupt:
+            raise
         except:
             self.cache = {}
 
index 8212061510d6ae0cb7161e65dd5de7a3d2e8f11c..4c4707800cc8bb38c975c690e53e9dab07f4ea61 100644 (file)
@@ -80,7 +80,7 @@ def get_calling_namespaces():
     """Return the locals and globals for the function that called
     into this module in the current callstack."""
     try: 1/0
-    except: frame = sys.exc_info()[2].tb_frame
+    except ZeroDivisionError: frame = sys.exc_info()[2].tb_frame
     
     while frame.f_globals.get("__name__") == __name__: frame = frame.f_back
 
index 613f7754d9f24d706a1ee7eb16d7fd9bdb9d22c3..03cb6d8a68465acd63fcb9f67ed5f227f99f74ce 100644 (file)
@@ -422,6 +422,8 @@ class OptParser(OptionParser):
                                                                   __main__.__date__,
                                                                   __main__.__developer__,
                                                                   __main__.__buildsys__))
+        except KeyboardInterrupt:
+            raise
         except:
             # On win32 there is no scons.py, so there is no __main__.__version__,
             # hence there is no script version.
@@ -740,7 +742,7 @@ def _main(args, parser):
         cdir = _create_path(options.directory)
         try:
             os.chdir(cdir)
-        except:
+        except OSError:
             sys.stderr.write("Could not change directory to %s\n" % cdir)
 
     xmit_args = []
index dfddf34114eda1f62dd607663239ec1d9d6e6194..a2ebd5cc32b4cff27f5d1fcb4ee3c915f32d9d0b 100644 (file)
@@ -117,7 +117,7 @@ class _SConsign:
         """
         try:
             return self.entries[filename]
-        except:
+        except (KeyError, AttributeError):
             return SConsignEntry()
 
     def set_entry(self, filename, entry):
@@ -198,6 +198,8 @@ class SConsignDB(_SConsign):
                 if type(self.entries) is not type({}):
                     self.entries = {}
                     raise TypeError
+            except KeyboardInterrupt:
+                raise
             except:
                 SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
                                     "Ignoring corrupt sconsign entry : %s"%self.dir.path)
@@ -244,11 +246,13 @@ class SConsignDirFile(SConsignDir):
 
         try:
             fp = open(self.sconsign, 'rb')
-        except:
+        except IOError:
             fp = None
 
         try:
             SConsignDir.__init__(self, fp, module)
+        except KeyboardInterrupt:
+            raise
         except:
             SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning,
                                 "Ignoring corrupt .sconsign file: %s"%self.sconsign)
@@ -274,11 +278,11 @@ class SConsignDirFile(SConsignDir):
             try:
                 file = open(temp, 'wb')
                 fname = temp
-            except:
+            except IOError:
                 try:
                     file = open(self.sconsign, 'wb')
                     fname = self.sconsign
-                except:
+                except IOError:
                     return
             cPickle.dump(self.entries, file, 1)
             file.close()
@@ -287,16 +291,16 @@ class SConsignDirFile(SConsignDir):
                     mode = os.stat(self.sconsign)[0]
                     os.chmod(self.sconsign, 0666)
                     os.unlink(self.sconsign)
-                except:
+                except OSError:
                     pass
                 try:
                     os.rename(fname, self.sconsign)
-                except:
+                except OSError:
                     open(self.sconsign, 'wb').write(open(fname, 'rb').read())
                     os.chmod(self.sconsign, mode)
             try:
                 os.unlink(temp)
-            except:
+            except OSError:
                 pass
 
 SConsignForDirectory = SConsignDirFile
index 6eda8c1b4772a9d69f75079bf1ec26464b59ee08..b269fa2e65033c1f1accad0d8869ae1535058500 100644 (file)
@@ -237,6 +237,8 @@ class Taskmaster:
                 self.candidates.pop()
                 self.ready = node
                 break
+            except KeyboardInterrupt:
+                raise
             except:
                 # We had a problem just trying to figure out the
                 # children (like a child couldn't be linked in to a
@@ -264,6 +266,8 @@ class Taskmaster:
             try:
                 def derived_nodes(node): return node.is_derived() or node.is_pseudo_derived()
                 derived = filter(derived_nodes, children)
+            except KeyboardInterrupt:
+                raise
             except:
                 # We had a problem just trying to figure out if any of
                 # the kids are derived (like a child couldn't be linked
@@ -343,6 +347,8 @@ class Taskmaster:
         task = self.tasker(self, tlist, node in self.targets, node)
         try:
             task.make_ready()
+        except KeyboardInterrupt:
+            raise
         except:
             # We had a problem just trying to get this task ready (like
             # a child couldn't be linked in to a BuildDir when deciding
index 5b650d6def28f878af508dde664092c4fe95d981..a38d4945bbea5f0f5b6f439308de119b60b8fa14 100644 (file)
@@ -44,7 +44,7 @@ acc = None
 
 try:
     dirs = os.listdir('/opt')
-except:
+except OSError:
     dirs = []
 
 for dir in dirs:
index 7468920d5b07b8a8c0bff38e385ac7fdd60972d2..2c7b55c08d8b6f6ce8d051983e8a17e958e6606b 100644 (file)
@@ -43,7 +43,7 @@ ccLinker = None
 
 try:
     dirs = os.listdir('/opt')
-except:
+except OSError:
     dirs = []
 
 for dir in dirs:
index ccb62f27335ffae91b6a1426c6bce7b25135dc25..93678e4c0974fa4638f9081efb314bf445e4ebc5 100644 (file)
@@ -55,7 +55,7 @@ def emit_java_headers(target, source, env):
         else:
             try:
                 classdir = s.attributes.java_classdir
-            except:
+            except AttributeError:
                 classdir = '.'
     classdir = SCons.Node.FS.default_fs.Dir(classdir).rdir()
     if str(classdir) == '.':
index db434c495e54d5500f96f8d9cb8928b831cdca2b..4b155686b03395023c2270ea806889a26c0d35ee 100644 (file)
@@ -301,6 +301,8 @@ def get_msvc_default_paths(version = None):
     try:
         if not version:
             version = SCons.Tool.msvs.get_visualstudio_versions()[0] #use highest version
+    except KeyboardInterrupt:
+        raise
     except:
         pass
 
index d4c32ba109dece3491d335f0061485853dc36076..68e8fda7437e8b5832a4b0abcdbaf0e56cb9ca9d 100644 (file)
@@ -317,6 +317,8 @@ class _GenerateV6DSP(_DSPGenerator):
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
@@ -334,6 +336,8 @@ class _GenerateV6DSP(_DSPGenerator):
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
@@ -474,6 +478,8 @@ class _GenerateV7DSP(_DSPGenerator):
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
@@ -490,6 +496,8 @@ class _GenerateV7DSP(_DSPGenerator):
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
@@ -567,6 +575,8 @@ class _GenerateV7DSW(_DSWGenerator):
         try:
             datas = base64.decodestring(datas)
             data = pickle.loads(datas)
+        except KeyboardInterrupt:
+            raise
         except:
             return # unable to unpickle any data for some reason
 
index 7043566dbd48c617e88a951f61cac0871f2dab03..79cc316abed4dcbe35ca597ffbfb0da039126f81 100644 (file)
@@ -55,7 +55,7 @@ def emit_rmic_classes(target, source, env):
         else:
             try:
                 classdir = s.attributes.java_classdir
-            except:
+            except AttributeError:
                 classdir = '.'
     classdir = SCons.Node.FS.default_fs.Dir(classdir).rdir()
     if str(classdir) == '.':
index f23917b2b1c83e404d8415bba3b2ec99f789735b..53dd410a19b4662919dd6c55b56a5302a2376a23 100644 (file)
@@ -43,7 +43,7 @@ ccLinker = None
 
 try:
     dirs = os.listdir('/opt')
-except:
+except OSError:
     dirs = []
 
 for dir in dirs:
index c0bc6ac4faadd6bf5ab8749a3bf68a54d717b9bd..41e3883ade1e28e45e3b3e1ccba9afa59c5535c5 100644 (file)
@@ -804,7 +804,7 @@ else:
             if os.path.isfile(f):
                 try:
                     st = os.stat(f)
-                except:
+                except OSError:
                     continue
                 if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
                     return os.path.normpath(f)