##// END OF EJS Templates
Merge pull request #7069 from jdemeyer/print_keyboardinterrupt...
Min RK -
r19200:7d035da0 merge
parent child Browse files
Show More
@@ -277,7 +277,7 b' class Pdb(OldPdb):'
277 try:
277 try:
278 OldPdb.interaction(self, frame, traceback)
278 OldPdb.interaction(self, frame, traceback)
279 except KeyboardInterrupt:
279 except KeyboardInterrupt:
280 self.shell.write("\nKeyboardInterrupt\n")
280 self.shell.write('\n' + self.shell.get_exception_only())
281 break
281 break
282 else:
282 else:
283 break
283 break
@@ -22,6 +22,7 b' import re'
22 import runpy
22 import runpy
23 import sys
23 import sys
24 import tempfile
24 import tempfile
25 import traceback
25 import types
26 import types
26 import subprocess
27 import subprocess
27 from io import open as io_open
28 from io import open as io_open
@@ -1786,6 +1787,15 b' class InteractiveShell(SingletonConfigurable):'
1786 """
1787 """
1787 self.write_err("UsageError: %s" % exc)
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 def showtraceback(self, exc_tuple=None, filename=None, tb_offset=None,
1799 def showtraceback(self, exc_tuple=None, filename=None, tb_offset=None,
1790 exception_only=False):
1800 exception_only=False):
1791 """Display the exception that just occurred.
1801 """Display the exception that just occurred.
@@ -1838,7 +1848,7 b' class InteractiveShell(SingletonConfigurable):'
1838 self._showtraceback(etype, value, stb)
1848 self._showtraceback(etype, value, stb)
1839
1849
1840 except KeyboardInterrupt:
1850 except KeyboardInterrupt:
1841 self.write_err("\nKeyboardInterrupt\n")
1851 self.write_err('\n' + self.get_exception_only())
1842
1852
1843 def _showtraceback(self, etype, evalue, stb):
1853 def _showtraceback(self, etype, evalue, stb):
1844 """Actually show a traceback.
1854 """Actually show a traceback.
@@ -2355,7 +2365,7 b' class InteractiveShell(SingletonConfigurable):'
2355 try:
2365 try:
2356 ec = os.system(cmd)
2366 ec = os.system(cmd)
2357 except KeyboardInterrupt:
2367 except KeyboardInterrupt:
2358 self.write_err("\nKeyboardInterrupt\n")
2368 self.write_err('\n' + self.get_exception_only())
2359 ec = -2
2369 ec = -2
2360 else:
2370 else:
2361 cmd = py3compat.unicode_to_str(cmd)
2371 cmd = py3compat.unicode_to_str(cmd)
@@ -2374,7 +2384,7 b' class InteractiveShell(SingletonConfigurable):'
2374 ec = subprocess.call(cmd, shell=True, executable=executable)
2384 ec = subprocess.call(cmd, shell=True, executable=executable)
2375 except KeyboardInterrupt:
2385 except KeyboardInterrupt:
2376 # intercept control-C; a long traceback is not useful here
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 ec = 130
2388 ec = 130
2379 if ec > 128:
2389 if ec > 128:
2380 ec = -(ec - 128)
2390 ec = -(ec - 128)
@@ -482,6 +482,24 b' class InteractiveShellTestCase(unittest.TestCase):'
482 mod = ip.new_main_mod(u'%s.py' % name, name)
482 mod = ip.new_main_mod(u'%s.py' % name, name)
483 self.assertEqual(mod.__name__, name)
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 if sys.version_info[0] <= 2:
499 self.assertEqual(msg, 'DerivedInterrupt: foo\n')
500 else:
501 self.assertEqual(msg, 'IPython.core.tests.test_interactiveshell.DerivedInterrupt: foo\n')
502
485 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
503 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
486
504
487 @onlyif_unicode_paths
505 @onlyif_unicode_paths
@@ -529,7 +529,7 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
529 except KeyboardInterrupt:
529 except KeyboardInterrupt:
530 #double-guard against keyboardinterrupts during kbdint handling
530 #double-guard against keyboardinterrupts during kbdint handling
531 try:
531 try:
532 self.write('\nKeyboardInterrupt\n')
532 self.write('\n' + self.get_exception_only())
533 source_raw = self.input_splitter.raw_reset()
533 source_raw = self.input_splitter.raw_reset()
534 hlen_b4_cell = self._replace_rlhist_multiline(source_raw, hlen_b4_cell)
534 hlen_b4_cell = self._replace_rlhist_multiline(source_raw, hlen_b4_cell)
535 more = False
535 more = False
@@ -468,7 +468,7 b' class TerminalInteractiveShell(InteractiveShell):'
468 except KeyboardInterrupt:
468 except KeyboardInterrupt:
469 #double-guard against keyboardinterrupts during kbdint handling
469 #double-guard against keyboardinterrupts during kbdint handling
470 try:
470 try:
471 self.write('\nKeyboardInterrupt\n')
471 self.write('\n' + self.get_exception_only())
472 source_raw = self.input_splitter.raw_reset()
472 source_raw = self.input_splitter.raw_reset()
473 hlen_b4_cell = \
473 hlen_b4_cell = \
474 self._replace_rlhist_multiline(source_raw, hlen_b4_cell)
474 self._replace_rlhist_multiline(source_raw, hlen_b4_cell)
General Comments 0
You need to be logged in to leave comments. Login now