##// END OF EJS Templates
Print exception instead of "KeyboardInterrupt"...
Jeroen Demeyer -
Show More
@@ -277,7 +277,7 b' class Pdb(OldPdb):'
277 277 try:
278 278 OldPdb.interaction(self, frame, traceback)
279 279 except KeyboardInterrupt:
280 self.shell.write("\nKeyboardInterrupt\n")
280 self.shell.write('\n' + self.shell.get_exception_only())
281 281 break
282 282 else:
283 283 break
@@ -22,6 +22,7 b' import re'
22 22 import runpy
23 23 import sys
24 24 import tempfile
25 import traceback
25 26 import types
26 27 import subprocess
27 28 from io import open as io_open
@@ -1786,6 +1787,15 b' class InteractiveShell(SingletonConfigurable):'
1786 1787 """
1787 1788 self.write_err("UsageError: %s" % exc)
1788 1789
1790 def get_exception_only(self, exc_tuple=None):
1791 """
1792 Return as a string (ending with a newline) the exception that
1793 just occurred, without any traceback.
1794 """
1795 etype, value, tb = self._get_exc_info(exc_tuple)
1796 msg = traceback.format_exception_only(etype, value)
1797 return ''.join(msg)
1798
1789 1799 def showtraceback(self, exc_tuple=None, filename=None, tb_offset=None,
1790 1800 exception_only=False):
1791 1801 """Display the exception that just occurred.
@@ -1838,7 +1848,7 b' class InteractiveShell(SingletonConfigurable):'
1838 1848 self._showtraceback(etype, value, stb)
1839 1849
1840 1850 except KeyboardInterrupt:
1841 self.write_err("\nKeyboardInterrupt\n")
1851 self.write_err('\n' + self.get_exception_only())
1842 1852
1843 1853 def _showtraceback(self, etype, evalue, stb):
1844 1854 """Actually show a traceback.
@@ -2355,7 +2365,7 b' class InteractiveShell(SingletonConfigurable):'
2355 2365 try:
2356 2366 ec = os.system(cmd)
2357 2367 except KeyboardInterrupt:
2358 self.write_err("\nKeyboardInterrupt\n")
2368 self.write_err('\n' + self.get_exception_only())
2359 2369 ec = -2
2360 2370 else:
2361 2371 cmd = py3compat.unicode_to_str(cmd)
@@ -2374,7 +2384,7 b' class InteractiveShell(SingletonConfigurable):'
2374 2384 ec = subprocess.call(cmd, shell=True, executable=executable)
2375 2385 except KeyboardInterrupt:
2376 2386 # intercept control-C; a long traceback is not useful here
2377 self.write_err("\nKeyboardInterrupt\n")
2387 self.write_err('\n' + self.get_exception_only())
2378 2388 ec = 130
2379 2389 if ec > 128:
2380 2390 ec = -(ec - 128)
@@ -482,6 +482,21 b' class InteractiveShellTestCase(unittest.TestCase):'
482 482 mod = ip.new_main_mod(u'%s.py' % name, name)
483 483 self.assertEqual(mod.__name__, name)
484 484
485 def test_get_exception_only(self):
486 try:
487 raise KeyboardInterrupt
488 except KeyboardInterrupt:
489 msg = ip.get_exception_only()
490 self.assertEqual(msg, 'KeyboardInterrupt\n')
491
492 class DerivedInterrupt(KeyboardInterrupt):
493 pass
494 try:
495 raise DerivedInterrupt("foo")
496 except KeyboardInterrupt:
497 msg = ip.get_exception_only()
498 self.assertEqual(msg, 'DerivedInterrupt: foo\n')
499
485 500 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
486 501
487 502 @onlyif_unicode_paths
@@ -529,7 +529,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
529 529 except KeyboardInterrupt:
530 530 #double-guard against keyboardinterrupts during kbdint handling
531 531 try:
532 self.write('\nKeyboardInterrupt\n')
532 self.write('\n' + self.get_exception_only())
533 533 source_raw = self.input_splitter.raw_reset()
534 534 hlen_b4_cell = self._replace_rlhist_multiline(source_raw, hlen_b4_cell)
535 535 more = False
@@ -468,7 +468,7 b' class TerminalInteractiveShell(InteractiveShell):'
468 468 except KeyboardInterrupt:
469 469 #double-guard against keyboardinterrupts during kbdint handling
470 470 try:
471 self.write('\nKeyboardInterrupt\n')
471 self.write('\n' + self.get_exception_only())
472 472 source_raw = self.input_splitter.raw_reset()
473 473 hlen_b4_cell = \
474 474 self._replace_rlhist_multiline(source_raw, hlen_b4_cell)
General Comments 0
You need to be logged in to leave comments. Login now