summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-09-03 17:11:03 -0700
committerZac Medico <zmedico@gentoo.org>2010-09-03 17:11:03 -0700
commit77fb8383288425e1b79d8092828da0b87e6293aa (patch)
treedee8bdc843b8b6549a65a84013506074339320f6
parent1959bfc2a30aa6160dfa0b454f3af0a545bf40f0 (diff)
downloadportage-77fb8383288425e1b79d8092828da0b87e6293aa.tar.gz
portage-77fb8383288425e1b79d8092828da0b87e6293aa.tar.bz2
portage-77fb8383288425e1b79d8092828da0b87e6293aa.zip
Add AlarmSignal.register() and unregister() classmethods in order to
handle interaction with the signal module.
-rwxr-xr-xbin/ebuild-ipc.py5
-rw-r--r--pym/portage/exception.py12
2 files changed, 13 insertions, 4 deletions
diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py
index b4a1f7767..b3d28a789 100755
--- a/bin/ebuild-ipc.py
+++ b/bin/ebuild-ipc.py
@@ -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):
diff --git a/pym/portage/exception.py b/pym/portage/exception.py
index b0f9ad8eb..dca1100e6 100644
--- a/pym/portage/exception.py
+++ b/pym/portage/exception.py
@@ -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)