diff mxtool/mx.py @ 4660:b06ade6e927c

Fixed Ctrl+C for Windows in mx.py
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 21 Feb 2012 19:30:33 +0100
parents 7903b6c28f9c
children 60a8f52c0be0
line wrap: on
line diff
--- a/mxtool/mx.py	Tue Feb 21 15:57:18 2012 +0100
+++ b/mxtool/mx.py	Tue Feb 21 19:30:33 2012 +0100
@@ -557,6 +557,17 @@
 # This is a tuple of the Popen object and args.
 _currentSubprocess = None
 
+def waitOn(p):
+    if get_os() == 'windows':
+        # on windows use a poll loop, otherwise signal does not get handled
+        retcode = None
+        while retcode == None:
+            retcode = p.poll()
+            time.sleep(0.05)
+    else:
+        retcode = p.wait()
+    return retcode
+
 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None):
     """
     Run a command in a subprocess, wait for it to complete and return the exit status of the process.
@@ -592,14 +603,7 @@
             # The preexec_fn=os.setsid
             p = subprocess.Popen(args, cwd=cwd, preexec_fn=preexec_fn, creationflags=creationflags)
             _currentSubprocess = (p, args)
-            if get_os() == 'windows':
-                # on windows use a poll loop, otherwise signal does not get handled
-                retcode = None
-                while retcode == None:
-                    retcode = p.poll()
-                    time.sleep(0.05)
-            else:
-                retcode = p.wait()            
+	    waitOn(p)
         else:
             def redirect(stream, f):
                 for line in iter(stream.readline, ''):
@@ -618,7 +622,7 @@
                 t.daemon = True # thread dies with the program
                 t.start()
             if timeout is None or timeout == 0:
-                retcode = p.wait()
+                retcode = waitOn(p)
             else:
                 if get_os() == 'windows':
                     abort('Use of timeout not (yet) supported on Windows')