public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: bin/, pym/_emerge/
Date: Sun, 14 Oct 2012 21:59:48 +0000 (UTC)	[thread overview]
Message-ID: <1350251973.8a8eda21d80099e74f38f5456f542611238f44a1.zmedico@gentoo> (raw)

commit:     8a8eda21d80099e74f38f5456f542611238f44a1
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 14 21:59:33 2012 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Oct 14 21:59:33 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=8a8eda21

emerge: handle KeyboardInterrupt, not SIGINT

We handle KeyboardInterrupt instead of installing a SIGINT handler,
since exiting from signal handlers intermittently causes python to
ignore the SystemExit exception with a message like this:

Exception SystemExit: 130 in <function remove at 0x7fd2146c1320> ignored

---
 bin/emerge          |   97 +++++++++++++++++++++++++++-----------------------
 pym/_emerge/main.py |    3 +-
 2 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/bin/emerge b/bin/emerge
index f618068..b749b0a 100755
--- a/bin/emerge
+++ b/bin/emerge
@@ -7,64 +7,71 @@ from __future__ import print_function
 import platform
 import signal
 import sys
-# This block ensures that ^C interrupts are handled quietly.
+
+# This block ensures that ^C interrupts are handled quietly. We handle
+# KeyboardInterrupt instead of installing a SIGINT handler, since
+# exiting from signal handlers intermittently causes python to ignore
+# the SystemExit exception with a message like this:
+# Exception SystemExit: 130 in <function remove at 0x7fd2146c1320> ignored
 try:
 
 	def exithandler(signum,frame):
-		signal.signal(signal.SIGINT, signal.SIG_IGN)
 		signal.signal(signal.SIGTERM, signal.SIG_IGN)
 		sys.exit(128 + signum)
 
-	signal.signal(signal.SIGINT, exithandler)
 	signal.signal(signal.SIGTERM, exithandler)
 	# Prevent "[Errno 32] Broken pipe" exceptions when
 	# writing to a pipe.
 	signal.signal(signal.SIGPIPE, signal.SIG_DFL)
 
-except KeyboardInterrupt:
-	sys.exit(128 + signal.SIGINT)
-
-def debug_signal(signum, frame):
-	import pdb
-	pdb.set_trace()
+	def debug_signal(signum, frame):
+		import pdb
+		pdb.set_trace()
 
-if platform.python_implementation() == 'Jython':
-	debug_signum = signal.SIGUSR2 # bug #424259
-else:
-	debug_signum = signal.SIGUSR1
+	if platform.python_implementation() == 'Jython':
+		debug_signum = signal.SIGUSR2 # bug #424259
+	else:
+		debug_signum = signal.SIGUSR1
 
-signal.signal(debug_signum, debug_signal)
+	signal.signal(debug_signum, debug_signal)
 
-from os import path as osp
-pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")
-sys.path.insert(0, pym_path)
-from _emerge.main import emerge_main
+	from os import path as osp
+	pym_path = osp.join(osp.dirname(osp.dirname(
+		osp.realpath(__file__))), "pym")
+	sys.path.insert(0, pym_path)
+	from _emerge.main import emerge_main
 
-if __name__ == "__main__":
-	import sys
-	from portage.exception import ParseError, PermissionDenied
-	try:
-		retval = emerge_main()
-	except PermissionDenied as e:
-		sys.stderr.write("Permission denied: '%s'\n" % str(e))
-		sys.exit(e.errno)
-	except ParseError as e:
-		sys.stderr.write("%s\n" % str(e))
-		sys.exit(1)
-	except SystemExit:
-		raise
-	except Exception:
-		# If an unexpected exception occurs then we don't want the mod_echo
-		# output to obscure the traceback, so dump the mod_echo output before
-		# showing the traceback.
-		import traceback
-		tb_str = traceback.format_exc()
+	if __name__ == "__main__":
+		import sys
+		from portage.exception import ParseError, PermissionDenied
 		try:
-			from portage.elog import mod_echo
-		except ImportError:
-			pass
-		else:
-			mod_echo.finalize()
-		sys.stderr.write(tb_str)
-		sys.exit(1)
-	sys.exit(retval)
+			retval = emerge_main()
+		except PermissionDenied as e:
+			sys.stderr.write("Permission denied: '%s'\n" % str(e))
+			sys.exit(e.errno)
+		except ParseError as e:
+			sys.stderr.write("%s\n" % str(e))
+			sys.exit(1)
+		except (KeyboardInterrupt, SystemExit):
+			raise
+		except Exception:
+			# If an unexpected exception occurs then we don't want the
+			# mod_echo output to obscure the traceback, so dump the
+			# mod_echo output before showing the traceback.
+			import traceback
+			tb_str = traceback.format_exc()
+			try:
+				from portage.elog import mod_echo
+			except ImportError:
+				pass
+			else:
+				mod_echo.finalize()
+			sys.stderr.write(tb_str)
+			sys.exit(1)
+		sys.exit(retval)
+
+except KeyboardInterrupt:
+	sys.stderr.write("\n\nExiting on signal %(signal)s\n" %
+		{"signal": signal.SIGINT})
+	sys.stderr.flush()
+	sys.exit(128 + signal.SIGINT)

diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py
index dad144c..adb6327 100644
--- a/pym/_emerge/main.py
+++ b/pym/_emerge/main.py
@@ -1955,11 +1955,10 @@ def emerge_main(args=None):
 	del oldargs
 
 	def emergeexitsig(signum, frame):
-		signal.signal(signal.SIGINT, signal.SIG_IGN)
 		signal.signal(signal.SIGTERM, signal.SIG_IGN)
 		portage.util.writemsg("\n\nExiting on signal %(signal)s\n" % {"signal":signum})
 		sys.exit(128 + signum)
-	signal.signal(signal.SIGINT, emergeexitsig)
+
 	signal.signal(signal.SIGTERM, emergeexitsig)
 
 	def emergeexit():


             reply	other threads:[~2012-10-14 21:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-14 21:59 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-04-30 19:28 [gentoo-commits] proj/portage:master commit in: bin/, pym/_emerge/ Zac Medico
2018-03-28  6:52 Zac Medico
2015-09-28 16:08 Zac Medico
2013-12-27 18:06 Arfrever Frehtes Taifersar Arahesis
2013-08-03  0:38 Zac Medico
2012-12-29  7:45 Zac Medico
2012-10-06 18:11 Zac Medico
2012-10-06 18:05 Zac Medico
2012-09-15 16:53 Zac Medico
2012-07-18 21:38 Zac Medico
2012-03-25 23:20 Zac Medico
2011-12-10  3:23 Zac Medico
2011-10-29  3:20 Zac Medico
2011-10-28 20:13 Zac Medico
2011-02-22  2:51 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350251973.8a8eda21d80099e74f38f5456f542611238f44a1.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox