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