##// END OF EJS Templates
More pythonw.exe-specific fixes to the kernel launching pipeline.
epatters -
Show More
@@ -63,8 +63,17 b' def make_argument_parser():'
63
63
64 def make_kernel(namespace, kernel_factory,
64 def make_kernel(namespace, kernel_factory,
65 out_stream_factory=None, display_hook_factory=None):
65 out_stream_factory=None, display_hook_factory=None):
66 """ Creates a kernel.
66 """ Creates a kernel, redirects stdout/stderr, and installs a display hook
67 and exception handler.
67 """
68 """
69 # If running under pythonw.exe, the interpreter will crash if more than 4KB
70 # of data is written to stdout or stderr. This is a bug that has been with
71 # Python for a very long time; see http://bugs.python.org/issue706263.
72 if sys.executable.endswith('pythonw.exe'):
73 blackhole = file(os.devnull, 'w')
74 sys.stdout = sys.stderr = blackhole
75 sys.__stdout__ = sys.__stderr__ = blackhole
76
68 # Install minimal exception handling
77 # Install minimal exception handling
69 sys.excepthook = FormattedTB(mode='Verbose', color_scheme='NoColor',
78 sys.excepthook = FormattedTB(mode='Verbose', color_scheme='NoColor',
70 ostream=sys.__stdout__)
79 ostream=sys.__stdout__)
@@ -192,10 +201,12 b' def base_launch_kernel(code, xrep_port=0, pub_port=0, req_port=0, hb_port=0,'
192
201
193 # Spawn a kernel.
202 # Spawn a kernel.
194 if sys.platform == 'win32':
203 if sys.platform == 'win32':
204
195 # If using pythonw, stdin, stdout, and stderr are invalid. Popen will
205 # If using pythonw, stdin, stdout, and stderr are invalid. Popen will
196 # fail unless they are suitably redirected. We don't read from the
206 # fail unless they are suitably redirected. We don't read from the
197 # pipes, but they must exist.
207 # pipes, but they must exist.
198 redirect = PIPE if sys.executable.endswith('pythonw.exe') else None
208 redirect = PIPE if sys.executable.endswith('pythonw.exe') else None
209
199 if independent:
210 if independent:
200 proc = Popen(['start', '/b'] + arguments, shell=True,
211 proc = Popen(['start', '/b'] + arguments, shell=True,
201 stdout=redirect, stderr=redirect, stdin=redirect)
212 stdout=redirect, stderr=redirect, stdin=redirect)
@@ -208,6 +219,13 b' def base_launch_kernel(code, xrep_port=0, pub_port=0, req_port=0, hb_port=0,'
208 DUPLICATE_SAME_ACCESS)
219 DUPLICATE_SAME_ACCESS)
209 proc = Popen(arguments + ['--parent', str(int(handle))],
220 proc = Popen(arguments + ['--parent', str(int(handle))],
210 stdout=redirect, stderr=redirect, stdin=redirect)
221 stdout=redirect, stderr=redirect, stdin=redirect)
222
223 # Clean up pipes created to work around Popen bug.
224 if redirect is not None:
225 proc.stdout.close()
226 proc.stderr.close()
227 proc.stdin.close()
228
211 else:
229 else:
212 if independent:
230 if independent:
213 proc = Popen(arguments, preexec_fn=lambda: os.setsid())
231 proc = Popen(arguments, preexec_fn=lambda: os.setsid())
General Comments 0
You need to be logged in to leave comments. Login now