diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 4bf2839..2e27f80 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2352,7 +2352,11 @@ class InteractiveShell(SingletonConfigurable): if path is not None: cmd = '"pushd %s &&"%s' % (path, cmd) cmd = py3compat.unicode_to_str(cmd) - ec = os.system(cmd) + try: + ec = os.system(cmd) + except KeyboardInterrupt: + self.write_err("\nKeyboardInterrupt\n") + ec = -2 else: cmd = py3compat.unicode_to_str(cmd) # For posix the result of the subprocess.call() below is an exit diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 18371cb..8374672 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -544,9 +544,9 @@ class TestSystemRaw(unittest.TestCase, ExitCodeChecks): cmd = u'''python -c "'åäö'" ''' ip.system_raw(cmd) - @mock.patch('subprocess.call') - def test_control_c(self, call_mock): - call_mock.side_effect = KeyboardInterrupt() + @mock.patch('subprocess.call', side_effect=KeyboardInterrupt) + @mock.patch('os.system', side_effect=KeyboardInterrupt) + def test_control_c(self, *mocks): try: self.system("sleep 1 # wont happen") except KeyboardInterrupt: