catch TERM signal in command processor
authormpm@selenic.com
Wed, 01 Jun 2005 13:04:13 -0800
changeset 214 2d60aa9bde0aba8ff1f746473d2db758449404f2
parent 213 d2172916ef6c64001cf747040dd625db89b61929
child 215 9ff5a78d0c45565dc329649ee7ffb0eba142804a
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
catch TERM signal in command processor -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 catch TERM signal in command processor This keeps kill from interrupting a transaction without cleanup. manifest hash: c50091696a3396dfed5c3168bd9e0d94c457a04b -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCniLNywK+sNU5EO8RAvepAKCCnEX7vPheIyOu2IvV6dDahdFMWACeMih6 E2R3rA/MGACxG9HpSNH6lak= =HR1s -----END PGP SIGNATURE-----
mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1,9 +1,9 @@
-import os, re, traceback, sys
+import os, re, traceback, sys, signal
 from mercurial import fancyopts, ui, hg
 
 class UnknownCommand(Exception): pass
 
 def filterfiles(list, files):
     l = [ x for x in list if x in files ]
 
     for f in files:
@@ -154,16 +154,21 @@ norepo = "init branch help"
 def find(cmd):
     i = None
     for e in table.keys():
         if re.match(e + "$", cmd):
             return table[e]
 
     raise UnknownCommand(cmd)
 
+class SignalInterrupt(Exception): pass
+
+def catchterm(*args):
+    raise SignalInterrupt
+
 def dispatch(args):
     options = {}
     opts = [('v', 'verbose', None, 'verbose'),
             ('d', 'debug', None, 'debug'),
             ('q', 'quiet', None, 'quiet'),
             ('y', 'noninteractive', None, 'run non-interactively'),
             ]
 
@@ -176,27 +181,31 @@ def dispatch(args):
         cmd, args = args[0], args[1:]
 
     u = ui.ui(options["verbose"], options["debug"], options["quiet"],
            not options["noninteractive"])
 
     # deal with unfound commands later
     i = find(cmd)
 
+    signal.signal(signal.SIGTERM, catchterm)
+
     cmdoptions = {}
     args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
 
     if cmd not in norepo.split():
         repo = hg.repository(ui = u)
         d = lambda: i[0](u, repo, *args, **cmdoptions)
     else:
         d = lambda: i[0](u, *args, **cmdoptions)
 
     try:
         d()
+    except SignalInterrupt:
+        u.warn("killed!\n")
     except KeyboardInterrupt:
         u.warn("interrupted!\n")
     except TypeError, inst:
         # was this an argument error?
         tb = traceback.extract_tb(sys.exc_info()[2])
         if len(tb) > 2: # no
             raise
         u.warn("%s: invalid arguments\n" % i[0].__name__)