Fix the rsync child process wait code
authorNikos Skalkotos <skalkoto@grnet.gr>
Thu, 10 Jan 2013 17:15:37 +0000 (19:15 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 10 Jan 2013 17:15:37 +0000 (19:15 +0200)
If the process takes too long to finish after the stdout fd is
closed, kill it.

image_creator/rsync.py

index 16f3c63..5d1d5c1 100644 (file)
@@ -124,12 +124,19 @@ class Rsync:
             progress.success('done')
 
         finally:
-            run.poll()
-            if run.returncode is None:
-                run.send_signal(signal.SIGHUP)
+            def handler(signum, frame):
+                run.terminate()
+                time.sleep(1)
+                run.poll()
+                if run.returncode is None:
+                    run.kill()
+                run.wait()
+
+            signal.signal(signal.SIGALRM, handler)
+            signal.alarm(2)
             run.communicate()
+            signal.alarm(0)
             if run.returncode != 0:
                 raise FatalError("rsync failed")
 
-
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :