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
level=logging.ERROR, noiselevel=-1)
return 1
finally:
- signal.alarm(0)
+ portage.exception.AlarmSignal.unregister()
portage.locks.unlockfile(lock_obj)
def _communicate(self, args):
# 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 _
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)