Show More
@@ -26,6 +26,13 b' from IPython.external.qt_for_kernel import QtCore, QtGui' | |||
|
26 | 26 | from IPython.lib.inputhook import allow_CTRL_C, ignore_CTRL_C, stdin_ready |
|
27 | 27 | |
|
28 | 28 | #----------------------------------------------------------------------------- |
|
29 | # Module Globals | |
|
30 | #----------------------------------------------------------------------------- | |
|
31 | ||
|
32 | got_kbdint = False | |
|
33 | sigint_timer = None | |
|
34 | ||
|
35 | #----------------------------------------------------------------------------- | |
|
29 | 36 | # Code |
|
30 | 37 | #----------------------------------------------------------------------------- |
|
31 | 38 | |
@@ -69,10 +76,6 b' def create_inputhook_qt4(mgr, app=None):' | |||
|
69 | 76 | # Otherwise create the inputhook_qt4/preprompthook_qt4 pair of |
|
70 | 77 | # hooks (they both share the got_kbdint flag) |
|
71 | 78 | |
|
72 | got_kbdint = [False] | |
|
73 | ||
|
74 | sigint_timer = [None] | |
|
75 | ||
|
76 | 79 | def inputhook_qt4(): |
|
77 | 80 | """PyOS_InputHook python hook for Qt4. |
|
78 | 81 | |
@@ -121,8 +124,10 b' def create_inputhook_qt4(mgr, app=None):' | |||
|
121 | 124 | event_loop.exec_() |
|
122 | 125 | timer.stop() |
|
123 | 126 | except KeyboardInterrupt: |
|
127 | global got_kbdint, sigint_timer | |
|
128 | ||
|
124 | 129 | ignore_CTRL_C() |
|
125 |
got_kbdint |
|
|
130 | got_kbdint = True | |
|
126 | 131 | mgr.clear_inputhook() |
|
127 | 132 | |
|
128 | 133 | # This generates a second SIGINT so the user doesn't have to |
@@ -136,10 +141,10 b' def create_inputhook_qt4(mgr, app=None):' | |||
|
136 | 141 | # Python and CTRL_C_EVENT doesn't work). |
|
137 | 142 | if(os.name == 'posix'): |
|
138 | 143 | pid = os.getpid() |
|
139 |
if(not sigint_timer |
|
|
140 |
sigint_timer |
|
|
144 | if(not sigint_timer): | |
|
145 | sigint_timer = threading.Timer(.01, os.kill, | |
|
141 | 146 | args=[pid, signal.SIGINT] ) |
|
142 |
sigint_timer |
|
|
147 | sigint_timer.start() | |
|
143 | 148 | else: |
|
144 | 149 | print("\nKeyboardInterrupt - Ctrl-C again for new prompt") |
|
145 | 150 | |
@@ -160,13 +165,15 b' def create_inputhook_qt4(mgr, app=None):' | |||
|
160 | 165 | (in case the latter was temporarily deactivated after a |
|
161 | 166 | CTRL+C) |
|
162 | 167 | """ |
|
163 |
|
|
|
164 | sigint_timer[0].cancel() | |
|
165 |
|
|
|
168 | global got_kbdint, sigint_timer | |
|
169 | ||
|
170 | if(sigint_timer): | |
|
171 | sigint_timer.cancel() | |
|
172 | sigint_timer = None | |
|
166 | 173 | |
|
167 |
if got_kbdint |
|
|
174 | if got_kbdint: | |
|
168 | 175 | mgr.set_inputhook(inputhook_qt4) |
|
169 |
got_kbdint |
|
|
176 | got_kbdint = False | |
|
170 | 177 | |
|
171 | 178 | ip._inputhook_qt4 = inputhook_qt4 |
|
172 | 179 | ip.set_hook('pre_prompt_hook', preprompthook_qt4) |
General Comments 0
You need to be logged in to leave comments.
Login now