We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IPython 5 shell does not react to SIGQUIT (CTRL + \)
In previous IPython versions it was possible to terminate an IPython session quickly by sending an `SIGQUIT`, i.e., by pressing <kbd>CTRL</kbd>+<kbd> \ </kbd>. This is useful when having an `embed()` in a loop with a large number of iterations. Pressing <kbd>CTRL</kbd>+<kbd>d</kbd> followed by <kbd>y</kbd> is not practical. Since `%kill_embedded` is currently also broken there is no convenient way to terminate the process.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `IPython/terminal/shortcuts.py`
Content:
```
1 import signal
2 import sys
3 
4 from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER
5 from prompt_toolkit.filters import (HasFocus, HasSelection, Condition,
6     ViInsertMode, EmacsInsertMode, HasCompletions)
7 from prompt_toolkit.filters.cli import ViMode
8 from prompt_toolkit.keys import Keys
9 from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
10 
11 from IPython.utils.decorators import undoc
12 
13 @Condition
14 def cursor_in_leading_ws(cli):
15     before = cli.application.buffer.document.current_line_before_cursor
16     return (not before) or before.isspace()
17 
18 def register_ipython_shortcuts(registry, shell):
19     """Set up the prompt_toolkit keyboard shortcuts for IPython"""
20     insert_mode = ViInsertMode() | EmacsInsertMode()
21 
22     # Ctrl+J == Enter, seemingly
23     registry.add_binding(Keys.ControlJ,
24                          filter=(HasFocus(DEFAULT_BUFFER)
25                                  & ~HasSelection()
26                                  & insert_mode
27                         ))(newline_or_execute_outer(shell))
28 
29     registry.add_binding(Keys.ControlP,
30                          filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)
31                         ))(previous_history_or_previous_completion)
32 
33     registry.add_binding(Keys.ControlN,
34                          filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)
35                         ))(next_history_or_next_completion)
36 
37     registry.add_binding(Keys.ControlG,
38                          filter=(HasFocus(DEFAULT_BUFFER) & HasCompletions()
39                         ))(dismiss_completion)
40 
41     registry.add_binding(Keys.ControlC, filter=HasFocus(DEFAULT_BUFFER)
42                         )(reset_buffer)
43 
44     registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER)
45                         )(reset_search_buffer)
46 
47     supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
48     registry.add_binding(Keys.ControlZ, filter=supports_suspend
49                         )(suspend_to_bg)
50 
51     # Ctrl+I == Tab
52     registry.add_binding(Keys.ControlI,
53                          filter=(HasFocus(DEFAULT_BUFFER)
54                                  & ~HasSelection()
55                                  & insert_mode
56                                  & cursor_in_leading_ws
57                         ))(indent_buffer)
58 
59     registry.add_binding(Keys.ControlO,
60                          filter=(HasFocus(DEFAULT_BUFFER)
61                                 & EmacsInsertMode()))(newline_with_copy_margin)
62 
63     if shell.display_completions == 'readlinelike':
64         registry.add_binding(Keys.ControlI,
65                              filter=(HasFocus(DEFAULT_BUFFER)
66                                      & ~HasSelection()
67                                      & insert_mode
68                                      & ~cursor_in_leading_ws
69                             ))(display_completions_like_readline)
70 
71     if sys.platform == 'win32':
72         registry.add_binding(Keys.ControlV,
73                              filter=(
74                              HasFocus(
75                              DEFAULT_BUFFER) & ~ViMode()
76                             ))(win_paste)
77 
78 
79 def newline_or_execute_outer(shell):
80     def newline_or_execute(event):
81         """When the user presses return, insert a newline or execute the code."""
82         b = event.current_buffer
83         d = b.document
84 
85         if b.complete_state:
86             cc = b.complete_state.current_completion
87             if cc:
88                 b.apply_completion(cc)
89             else:
90                 b.cancel_completion()
91             return
92 
93         if not (d.on_last_line or d.cursor_position_row >= d.line_count
94             - d.empty_line_count_at_the_end()):
95             b.newline()
96             return
97 
98         status, indent = shell.input_splitter.check_complete(d.text + '\n')
99 
100         if (status != 'incomplete') and b.accept_action.is_returnable:
101             b.accept_action.validate_and_handle(event.cli, b)
102         else:
103             b.insert_text('\n' + (' ' * (indent or 0)))
104     return newline_or_execute
105 
106 
107 def previous_history_or_previous_completion(event):
108     """
109     Control-P in vi edit mode on readline is history next, unlike default prompt toolkit.
110 
111     If completer is open this still select previous completion.
112     """
113     event.current_buffer.auto_up()
114 
115 
116 def next_history_or_next_completion(event):
117     """
118     Control-N in vi edit mode on readline is history previous, unlike default prompt toolkit.
119 
120     If completer is open this still select next completion.
121     """
122     event.current_buffer.auto_down()
123 
124 
125 def dismiss_completion(event):
126     b = event.current_buffer
127     if b.complete_state:
128         b.cancel_completion()
129 
130 
131 def reset_buffer(event):
132     b = event.current_buffer
133     if b.complete_state:
134         b.cancel_completion()
135     else:
136         b.reset()
137 
138 
139 def reset_search_buffer(event):
140     if event.current_buffer.document.text:
141         event.current_buffer.reset()
142     else:
143         event.cli.push_focus(DEFAULT_BUFFER)
144 
145 def suspend_to_bg(event):
146     event.cli.suspend_to_background()
147 
148 def indent_buffer(event):
149     event.current_buffer.insert_text(' ' * 4)
150 
151 def newline_with_copy_margin(event):
152     """
153     Preserve margin and cursor position when using
154     Control-O to insert a newline in EMACS mode
155     """
156     b = event.current_buffer
157     cursor_start_pos = b.document.cursor_position_col
158     b.newline(copy_margin=True)
159     b.cursor_up(count=1)
160     cursor_end_pos = b.document.cursor_position_col
161     if cursor_start_pos != cursor_end_pos:
162         pos_diff = cursor_start_pos - cursor_end_pos
163         b.cursor_right(count=pos_diff)
164 
165 
166 
167 
168 if sys.platform == 'win32':
169     from IPython.core.error import TryNext
170     from IPython.lib.clipboard import (ClipboardEmpty,
171                                        win32_clipboard_get,
172                                        tkinter_clipboard_get)
173 
174     @undoc
175     def win_paste(event):
176         try:
177             text = win32_clipboard_get()
178         except TryNext:
179             try:
180                 text = tkinter_clipboard_get()
181             except (TryNext, ClipboardEmpty):
182                 return
183         except ClipboardEmpty:
184             return
185         event.current_buffer.insert_text(text.replace('\t', ' ' * 4))
186
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py
--- a/IPython/terminal/shortcuts.py
+++ b/IPython/terminal/shortcuts.py
@@ -26,6 +26,8 @@
                                  & insert_mode
                         ))(newline_or_execute_outer(shell))
 
+    registry.add_binding(Keys.ControlBackslash)(force_exit)
+
     registry.add_binding(Keys.ControlP,
                          filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)
                         ))(previous_history_or_previous_completion)
@@ -145,6 +147,12 @@
 def suspend_to_bg(event):
     event.cli.suspend_to_background()
 
+def force_exit(event):
+    """
+    Force exit (with a non-zero return value)
+    """
+    sys.exit("Quit")
+
 def indent_buffer(event):
     event.current_buffer.insert_text(' ' * 4)

{"golden_diff": "diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py\n--- a/IPython/terminal/shortcuts.py\n+++ b/IPython/terminal/shortcuts.py\n@@ -26,6 +26,8 @@\n                                  & insert_mode\n                         ))(newline_or_execute_outer(shell))\n \n+    registry.add_binding(Keys.ControlBackslash)(force_exit)\n+\n     registry.add_binding(Keys.ControlP,\n                          filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)\n                         ))(previous_history_or_previous_completion)\n@@ -145,6 +147,12 @@\n def suspend_to_bg(event):\n     event.cli.suspend_to_background()\n \n+def force_exit(event):\n+    \"\"\"\n+    Force exit (with a non-zero return value)\n+    \"\"\"\n+    sys.exit(\"Quit\")\n+\n def indent_buffer(event):\n     event.current_buffer.insert_text(' ' * 4)\n", "issue": "IPython 5 shell does not react to SIGQUIT (CTRL + \\)\nIn previous IPython versions it was possible to terminate an IPython session quickly by sending an `SIGQUIT`, i.e., by pressing <kbd>CTRL</kbd>+<kbd> \\ </kbd>. This is useful when having an `embed()` in a loop with a large number of iterations. Pressing <kbd>CTRL</kbd>+<kbd>d</kbd> followed by <kbd>y</kbd> is not practical. Since `%kill_embedded` is currently also broken there is no convenient way to terminate the process.\n\n", "before_files": [{"content": "import signal\nimport sys\n\nfrom prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER\nfrom prompt_toolkit.filters import (HasFocus, HasSelection, Condition,\n    ViInsertMode, EmacsInsertMode, HasCompletions)\nfrom prompt_toolkit.filters.cli import ViMode\nfrom prompt_toolkit.keys import Keys\nfrom prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline\n\nfrom IPython.utils.decorators import undoc\n\n@Condition\ndef cursor_in_leading_ws(cli):\n    before = cli.application.buffer.document.current_line_before_cursor\n    return (not before) or before.isspace()\n\ndef register_ipython_shortcuts(registry, shell):\n    \"\"\"Set up the prompt_toolkit keyboard shortcuts for IPython\"\"\"\n    insert_mode = ViInsertMode() | EmacsInsertMode()\n\n    # Ctrl+J == Enter, seemingly\n    registry.add_binding(Keys.ControlJ,\n                         filter=(HasFocus(DEFAULT_BUFFER)\n                                 & ~HasSelection()\n                                 & insert_mode\n                        ))(newline_or_execute_outer(shell))\n\n    registry.add_binding(Keys.ControlP,\n                         filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)\n                        ))(previous_history_or_previous_completion)\n\n    registry.add_binding(Keys.ControlN,\n                         filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)\n                        ))(next_history_or_next_completion)\n\n    registry.add_binding(Keys.ControlG,\n                         filter=(HasFocus(DEFAULT_BUFFER) & HasCompletions()\n                        ))(dismiss_completion)\n\n    registry.add_binding(Keys.ControlC, filter=HasFocus(DEFAULT_BUFFER)\n                        )(reset_buffer)\n\n    registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER)\n                        )(reset_search_buffer)\n\n    supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))\n    registry.add_binding(Keys.ControlZ, filter=supports_suspend\n                        )(suspend_to_bg)\n\n    # Ctrl+I == Tab\n    registry.add_binding(Keys.ControlI,\n                         filter=(HasFocus(DEFAULT_BUFFER)\n                                 & ~HasSelection()\n                                 & insert_mode\n                                 & cursor_in_leading_ws\n                        ))(indent_buffer)\n\n    registry.add_binding(Keys.ControlO,\n                         filter=(HasFocus(DEFAULT_BUFFER)\n                                & EmacsInsertMode()))(newline_with_copy_margin)\n\n    if shell.display_completions == 'readlinelike':\n        registry.add_binding(Keys.ControlI,\n                             filter=(HasFocus(DEFAULT_BUFFER)\n                                     & ~HasSelection()\n                                     & insert_mode\n                                     & ~cursor_in_leading_ws\n                            ))(display_completions_like_readline)\n\n    if sys.platform == 'win32':\n        registry.add_binding(Keys.ControlV,\n                             filter=(\n                             HasFocus(\n                             DEFAULT_BUFFER) & ~ViMode()\n                            ))(win_paste)\n\n\ndef newline_or_execute_outer(shell):\n    def newline_or_execute(event):\n        \"\"\"When the user presses return, insert a newline or execute the code.\"\"\"\n        b = event.current_buffer\n        d = b.document\n\n        if b.complete_state:\n            cc = b.complete_state.current_completion\n            if cc:\n                b.apply_completion(cc)\n            else:\n                b.cancel_completion()\n            return\n\n        if not (d.on_last_line or d.cursor_position_row >= d.line_count\n            - d.empty_line_count_at_the_end()):\n            b.newline()\n            return\n\n        status, indent = shell.input_splitter.check_complete(d.text + '\\n')\n\n        if (status != 'incomplete') and b.accept_action.is_returnable:\n            b.accept_action.validate_and_handle(event.cli, b)\n        else:\n            b.insert_text('\\n' + (' ' * (indent or 0)))\n    return newline_or_execute\n\n\ndef previous_history_or_previous_completion(event):\n    \"\"\"\n    Control-P in vi edit mode on readline is history next, unlike default prompt toolkit.\n\n    If completer is open this still select previous completion.\n    \"\"\"\n    event.current_buffer.auto_up()\n\n\ndef next_history_or_next_completion(event):\n    \"\"\"\n    Control-N in vi edit mode on readline is history previous, unlike default prompt toolkit.\n\n    If completer is open this still select next completion.\n    \"\"\"\n    event.current_buffer.auto_down()\n\n\ndef dismiss_completion(event):\n    b = event.current_buffer\n    if b.complete_state:\n        b.cancel_completion()\n\n\ndef reset_buffer(event):\n    b = event.current_buffer\n    if b.complete_state:\n        b.cancel_completion()\n    else:\n        b.reset()\n\n\ndef reset_search_buffer(event):\n    if event.current_buffer.document.text:\n        event.current_buffer.reset()\n    else:\n        event.cli.push_focus(DEFAULT_BUFFER)\n\ndef suspend_to_bg(event):\n    event.cli.suspend_to_background()\n\ndef indent_buffer(event):\n    event.current_buffer.insert_text(' ' * 4)\n\ndef newline_with_copy_margin(event):\n    \"\"\"\n    Preserve margin and cursor position when using\n    Control-O to insert a newline in EMACS mode\n    \"\"\"\n    b = event.current_buffer\n    cursor_start_pos = b.document.cursor_position_col\n    b.newline(copy_margin=True)\n    b.cursor_up(count=1)\n    cursor_end_pos = b.document.cursor_position_col\n    if cursor_start_pos != cursor_end_pos:\n        pos_diff = cursor_start_pos - cursor_end_pos\n        b.cursor_right(count=pos_diff)\n\n\n\n\nif sys.platform == 'win32':\n    from IPython.core.error import TryNext\n    from IPython.lib.clipboard import (ClipboardEmpty,\n                                       win32_clipboard_get,\n                                       tkinter_clipboard_get)\n\n    @undoc\n    def win_paste(event):\n        try:\n            text = win32_clipboard_get()\n        except TryNext:\n            try:\n                text = tkinter_clipboard_get()\n            except (TryNext, ClipboardEmpty):\n                return\n        except ClipboardEmpty:\n            return\n        event.current_buffer.insert_text(text.replace('\\t', ' ' * 4))\n", "path": "IPython/terminal/shortcuts.py"}], "after_files": [{"content": "import signal\nimport sys\n\nfrom prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER\nfrom prompt_toolkit.filters import (HasFocus, HasSelection, Condition,\n    ViInsertMode, EmacsInsertMode, HasCompletions)\nfrom prompt_toolkit.filters.cli import ViMode\nfrom prompt_toolkit.keys import Keys\nfrom prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline\n\nfrom IPython.utils.decorators import undoc\n\n@Condition\ndef cursor_in_leading_ws(cli):\n    before = cli.application.buffer.document.current_line_before_cursor\n    return (not before) or before.isspace()\n\ndef register_ipython_shortcuts(registry, shell):\n    \"\"\"Set up the prompt_toolkit keyboard shortcuts for IPython\"\"\"\n    insert_mode = ViInsertMode() | EmacsInsertMode()\n\n    # Ctrl+J == Enter, seemingly\n    registry.add_binding(Keys.ControlJ,\n                         filter=(HasFocus(DEFAULT_BUFFER)\n                                 & ~HasSelection()\n                                 & insert_mode\n                        ))(newline_or_execute_outer(shell))\n\n    registry.add_binding(Keys.ControlBackslash)(force_exit)\n\n    registry.add_binding(Keys.ControlP,\n                         filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)\n                        ))(previous_history_or_previous_completion)\n\n    registry.add_binding(Keys.ControlN,\n                         filter=(ViInsertMode() & HasFocus(DEFAULT_BUFFER)\n                        ))(next_history_or_next_completion)\n\n    registry.add_binding(Keys.ControlG,\n                         filter=(HasFocus(DEFAULT_BUFFER) & HasCompletions()\n                        ))(dismiss_completion)\n\n    registry.add_binding(Keys.ControlC, filter=HasFocus(DEFAULT_BUFFER)\n                        )(reset_buffer)\n\n    registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER)\n                        )(reset_search_buffer)\n\n    supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))\n    registry.add_binding(Keys.ControlZ, filter=supports_suspend\n                        )(suspend_to_bg)\n\n    # Ctrl+I == Tab\n    registry.add_binding(Keys.ControlI,\n                         filter=(HasFocus(DEFAULT_BUFFER)\n                                 & ~HasSelection()\n                                 & insert_mode\n                                 & cursor_in_leading_ws\n                        ))(indent_buffer)\n\n    registry.add_binding(Keys.ControlO,\n                         filter=(HasFocus(DEFAULT_BUFFER)\n                                & EmacsInsertMode()))(newline_with_copy_margin)\n\n    if shell.display_completions == 'readlinelike':\n        registry.add_binding(Keys.ControlI,\n                             filter=(HasFocus(DEFAULT_BUFFER)\n                                     & ~HasSelection()\n                                     & insert_mode\n                                     & ~cursor_in_leading_ws\n                            ))(display_completions_like_readline)\n\n    if sys.platform == 'win32':\n        registry.add_binding(Keys.ControlV,\n                             filter=(\n                             HasFocus(\n                             DEFAULT_BUFFER) & ~ViMode()\n                            ))(win_paste)\n\n\ndef newline_or_execute_outer(shell):\n    def newline_or_execute(event):\n        \"\"\"When the user presses return, insert a newline or execute the code.\"\"\"\n        b = event.current_buffer\n        d = b.document\n\n        if b.complete_state:\n            cc = b.complete_state.current_completion\n            if cc:\n                b.apply_completion(cc)\n            else:\n                b.cancel_completion()\n            return\n\n        if not (d.on_last_line or d.cursor_position_row >= d.line_count\n            - d.empty_line_count_at_the_end()):\n            b.newline()\n            return\n\n        status, indent = shell.input_splitter.check_complete(d.text + '\\n')\n\n        if (status != 'incomplete') and b.accept_action.is_returnable:\n            b.accept_action.validate_and_handle(event.cli, b)\n        else:\n            b.insert_text('\\n' + (' ' * (indent or 0)))\n    return newline_or_execute\n\n\ndef previous_history_or_previous_completion(event):\n    \"\"\"\n    Control-P in vi edit mode on readline is history next, unlike default prompt toolkit.\n\n    If completer is open this still select previous completion.\n    \"\"\"\n    event.current_buffer.auto_up()\n\n\ndef next_history_or_next_completion(event):\n    \"\"\"\n    Control-N in vi edit mode on readline is history previous, unlike default prompt toolkit.\n\n    If completer is open this still select next completion.\n    \"\"\"\n    event.current_buffer.auto_down()\n\n\ndef dismiss_completion(event):\n    b = event.current_buffer\n    if b.complete_state:\n        b.cancel_completion()\n\n\ndef reset_buffer(event):\n    b = event.current_buffer\n    if b.complete_state:\n        b.cancel_completion()\n    else:\n        b.reset()\n\n\ndef reset_search_buffer(event):\n    if event.current_buffer.document.text:\n        event.current_buffer.reset()\n    else:\n        event.cli.push_focus(DEFAULT_BUFFER)\n\ndef suspend_to_bg(event):\n    event.cli.suspend_to_background()\n\ndef force_exit(event):\n    \"\"\"\n    Force exit (with a non-zero return value)\n    \"\"\"\n    sys.exit(\"Quit\")\n\ndef indent_buffer(event):\n    event.current_buffer.insert_text(' ' * 4)\n\ndef newline_with_copy_margin(event):\n    \"\"\"\n    Preserve margin and cursor position when using\n    Control-O to insert a newline in EMACS mode\n    \"\"\"\n    b = event.current_buffer\n    cursor_start_pos = b.document.cursor_position_col\n    b.newline(copy_margin=True)\n    b.cursor_up(count=1)\n    cursor_end_pos = b.document.cursor_position_col\n    if cursor_start_pos != cursor_end_pos:\n        pos_diff = cursor_start_pos - cursor_end_pos\n        b.cursor_right(count=pos_diff)\n\n\n\n\nif sys.platform == 'win32':\n    from IPython.core.error import TryNext\n    from IPython.lib.clipboard import (ClipboardEmpty,\n                                       win32_clipboard_get,\n                                       tkinter_clipboard_get)\n\n    @undoc\n    def win_paste(event):\n        try:\n            text = win32_clipboard_get()\n        except TryNext:\n            try:\n                text = tkinter_clipboard_get()\n            except (TryNext, ClipboardEmpty):\n                return\n        except ClipboardEmpty:\n            return\n        event.current_buffer.insert_text(text.replace('\\t', ' ' * 4))\n", "path": "IPython/terminal/shortcuts.py"}]}