Show More
@@ -63,8 +63,17 b' def make_argument_parser():' | |||
|
63 | 63 | |
|
64 | 64 | def make_kernel(namespace, kernel_factory, |
|
65 | 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 | 77 | # Install minimal exception handling |
|
69 | 78 | sys.excepthook = FormattedTB(mode='Verbose', color_scheme='NoColor', |
|
70 | 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 | 202 | # Spawn a kernel. |
|
194 | 203 | if sys.platform == 'win32': |
|
204 | ||
|
195 | 205 | # If using pythonw, stdin, stdout, and stderr are invalid. Popen will |
|
196 | 206 | # fail unless they are suitably redirected. We don't read from the |
|
197 | 207 | # pipes, but they must exist. |
|
198 | 208 | redirect = PIPE if sys.executable.endswith('pythonw.exe') else None |
|
209 | ||
|
199 | 210 | if independent: |
|
200 | 211 | proc = Popen(['start', '/b'] + arguments, shell=True, |
|
201 | 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 | 219 | DUPLICATE_SAME_ACCESS) |
|
209 | 220 | proc = Popen(arguments + ['--parent', str(int(handle))], |
|
210 | 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 | 229 | else: |
|
212 | 230 | if independent: |
|
213 | 231 | proc = Popen(arguments, preexec_fn=lambda: os.setsid()) |
General Comments 0
You need to be logged in to leave comments.
Login now