From 77fb8383288425e1b79d8092828da0b87e6293aa Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 3 Sep 2010 17:11:03 -0700 Subject: Add AlarmSignal.register() and unregister() classmethods in order to handle interaction with the signal module. --- pym/portage/exception.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'pym/portage/exception.py') 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) -- cgit v1.2.3-1-g7c22