Add AlarmSignal.register() and unregister() classmethods in order to
authorZac Medico <zmedico@gentoo.org>
Sat, 4 Sep 2010 00:11:03 +0000 (17:11 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 4 Sep 2010 00:11:03 +0000 (17:11 -0700)
handle interaction with the signal module.

bin/ebuild-ipc.py
pym/portage/exception.py

index b4a1f7767b44a5e79bf718cb1043fce72a36ea69..b3d28a789a1c2c5f760006d692d6ad7da3e27863 100755 (executable)
@@ -49,10 +49,9 @@ class EbuildIpc(object):
                start_time = time.time()
 
                try:
-                       signal.signal(signal.SIGALRM, portage.exception.AlarmSignal.signal_handler)
+                       portage.exception.AlarmSignal.register()
                        signal.alarm(self._COMMUNICATE_TIMEOUT_SECONDS)
                        returncode = self._communicate(args)
-                       signal.alarm(0)
                        return returncode
                except portage.exception.AlarmSignal:
                        time_elapsed = time.time() - start_time
@@ -62,7 +61,7 @@ class EbuildIpc(object):
                                level=logging.ERROR, noiselevel=-1)
                        return 1
                finally:
-                       signal.alarm(0)
+                       portage.exception.AlarmSignal.unregister()
                        portage.locks.unlockfile(lock_obj)
 
        def _communicate(self, args):
index b0f9ad8eb13aed31566685a3eacca01c4d3e2294..dca1100e6e9e82a9f6c8ca0f2aea7de4a95fdac4 100644 (file)
@@ -1,6 +1,7 @@
 # Copyright 1998-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import signal
 import sys
 from portage import _unicode_encode, _unicode_decode
 from portage.localization import _
@@ -90,7 +91,16 @@ class AlarmSignal(TimeoutException):
                self.frame = frame
 
        @classmethod
-       def signal_handler(cls, signum, frame):
+       def register(cls):
+               signal.signal(signal.SIGALRM, cls._signal_handler)
+
+       @classmethod
+       def unregister(cls):
+               signal.alarm(0)
+               signal.signal(signal.SIGALRM, signal.SIG_DFL)
+
+       @classmethod
+       def _signal_handler(cls, signum, frame):
                raise AlarmSignal("alarm signal",
                        signum=signum, frame=frame)