From aa1a86304a80cf90a4623baa62a2a2e0b5346530 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Wed, 6 Oct 2010 12:05:14 +0400 Subject: [PATCH] Bugfix: catch SIGINT for rsync. --- pym/cl_distr.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pym/cl_distr.py b/pym/cl_distr.py index cff7a70..1e7c3ff 100644 --- a/pym/cl_distr.py +++ b/pym/cl_distr.py @@ -37,16 +37,27 @@ lang().setLanguage(sys.modules[__name__]) class SignalInterrupt: + __interruptProcessObjs = [] __sigint = False def setSignalInterrupt(self): + """Handler "SIGINT""" if SignalInterrupt.__sigint is False: sys.stdout.write("\b\b") + # killed processes + while (SignalInterrupt.__interruptProcessObjs): + process = SignalInterrupt.__interruptProcessObjs.pop() + if hasattr(process, "pipe") and hasattr(process.pipe,"kill"): + process.pipe.kill() SignalInterrupt.__sigint = True def getSignalInterrupt(self): return SignalInterrupt.__sigint + def addInterruptProcess(self, process): + SignalInterrupt.__interruptProcessObjs.append(process) + + class Spinner(threading.Thread): stopSignal = threading.Event() sequence= map(lambda x:x,iter("/-\\|")) @@ -407,6 +418,7 @@ class Distributive(object, SignalInterrupt): try: rsyncProcess = process("/usr/bin/rsync", "-a", "-x", "%s/"%fromdir,"%s/"%todir,stderr=STDOUT) + self.addInterruptProcess(rsyncProcess) res = rsyncProcess.success() errmes = rsyncProcess.read() except Exception,e: