Show More
@@ -23,6 +23,7 b' from iostream import OutStream' | |||
|
23 | 23 | from parentpoller import ParentPollerUnix, ParentPollerWindows |
|
24 | 24 | from session import Session |
|
25 | 25 | |
|
26 | ||
|
26 | 27 | def bind_port(socket, ip, port): |
|
27 | 28 | """ Binds the specified ZMQ socket. If the port is zero, a random port is |
|
28 | 29 | chosen. Returns the port that was bound. |
@@ -155,6 +156,7 b' def make_default_main(kernel_factory):' | |||
|
155 | 156 | |
|
156 | 157 | |
|
157 | 158 | def base_launch_kernel(code, xrep_port=0, pub_port=0, req_port=0, hb_port=0, |
|
159 | stdin=None, stdout=None, stderr=None, | |
|
158 | 160 | executable=None, independent=False, extra_arguments=[]): |
|
159 | 161 | """ Launches a localhost kernel, binding to the specified ports. |
|
160 | 162 | |
@@ -175,6 +177,9 b' def base_launch_kernel(code, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
175 | 177 | hb_port : int, optional |
|
176 | 178 | The port to use for the hearbeat REP channel. |
|
177 | 179 | |
|
180 | stdin, stdout, stderr : optional (default None) | |
|
181 | Standards streams, as defined in subprocess.Popen. | |
|
182 | ||
|
178 | 183 | executable : str, optional (default sys.executable) |
|
179 | 184 | The Python executable to use for the kernel process. |
|
180 | 185 | |
@@ -231,12 +236,19 b' def base_launch_kernel(code, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
231 | 236 | # If using pythonw, stdin, stdout, and stderr are invalid. Popen will |
|
232 | 237 | # fail unless they are suitably redirected. We don't read from the |
|
233 | 238 | # pipes, but they must exist. |
|
234 |
|
|
|
239 | if executable.endswith('pythonw.exe'): | |
|
240 | redirect = True | |
|
241 | _stdin = PIPE if stdin is None else stdin | |
|
242 | _stdout = PIPE if stdout is None else stdout | |
|
243 | _stderr = PIPE if stderr is None else stderr | |
|
244 | else: | |
|
245 | redirect = False | |
|
246 | _stdin, _stdout, _stderr = stdin, stdout, stderr | |
|
235 | 247 | |
|
236 | 248 | if independent: |
|
237 | 249 | proc = Popen(arguments, |
|
238 | 250 | creationflags=512, # CREATE_NEW_PROCESS_GROUP |
|
239 |
stdout= |
|
|
251 | stdin=_stdin, stdout=_stdout, stderr=_stderr) | |
|
240 | 252 | else: |
|
241 | 253 | from _subprocess import DuplicateHandle, GetCurrentProcess, \ |
|
242 | 254 | DUPLICATE_SAME_ACCESS |
@@ -245,21 +257,26 b' def base_launch_kernel(code, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
245 | 257 | True, # Inheritable by new processes. |
|
246 | 258 | DUPLICATE_SAME_ACCESS) |
|
247 | 259 | proc = Popen(arguments + ['--parent', str(int(handle))], |
|
248 |
stdout= |
|
|
260 | stdin=_stdin, stdout=_stdout, stderr=_stderr) | |
|
249 | 261 | |
|
250 | 262 | # Attach the interrupt event to the Popen objet so it can be used later. |
|
251 | 263 | proc.win32_interrupt_event = interrupt_event |
|
252 | 264 | |
|
253 | 265 | # Clean up pipes created to work around Popen bug. |
|
254 |
if redirect |
|
|
266 | if redirect: | |
|
267 | if stdin is None: | |
|
268 | proc.stdin.close() | |
|
269 | if stdout is None: | |
|
255 | 270 | proc.stdout.close() |
|
271 | if stderr is None: | |
|
256 | 272 | proc.stderr.close() |
|
257 | proc.stdin.close() | |
|
258 | 273 | |
|
259 | 274 | else: |
|
260 | 275 | if independent: |
|
261 |
proc = Popen(arguments, preexec_fn=lambda: os.setsid() |
|
|
276 | proc = Popen(arguments, preexec_fn=lambda: os.setsid(), | |
|
277 | stdin=stdin, stdout=stdout, stderr=stderr) | |
|
262 | 278 | else: |
|
263 |
proc = Popen(arguments + ['--parent'] |
|
|
279 | proc = Popen(arguments + ['--parent'], | |
|
280 | stdin=stdin, stdout=stdout, stderr=stderr) | |
|
264 | 281 | |
|
265 | 282 | return proc, xrep_port, pub_port, req_port, hb_port |
@@ -551,6 +551,7 b' class GTKKernel(Kernel):' | |||
|
551 | 551 | #----------------------------------------------------------------------------- |
|
552 | 552 | |
|
553 | 553 | def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0, |
|
554 | stdin=None, stdout=None, stderr=None, | |
|
554 | 555 | executable=None, independent=False, pylab=False, colors=None): |
|
555 | 556 | """Launches a localhost kernel, binding to the specified ports. |
|
556 | 557 | |
@@ -571,6 +572,9 b' def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
571 | 572 | hb_port : int, optional |
|
572 | 573 | The port to use for the hearbeat REP channel. |
|
573 | 574 | |
|
575 | stdin, stdout, stderr : optional (default None) | |
|
576 | Standards streams, as defined in subprocess.Popen. | |
|
577 | ||
|
574 | 578 | executable : str, optional (default sys.executable) |
|
575 | 579 | The Python executable to use for the kernel process. |
|
576 | 580 | |
@@ -608,6 +612,7 b' def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
608 | 612 | extra_arguments.append(colors) |
|
609 | 613 | return base_launch_kernel('from IPython.zmq.ipkernel import main; main()', |
|
610 | 614 | xrep_port, pub_port, req_port, hb_port, |
|
615 | stdin, stdout, stderr, | |
|
611 | 616 | executable, independent, extra_arguments) |
|
612 | 617 | |
|
613 | 618 |
@@ -248,6 +248,7 b' class Kernel(HasTraits):' | |||
|
248 | 248 | #----------------------------------------------------------------------------- |
|
249 | 249 | |
|
250 | 250 | def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0, |
|
251 | stdin=None, stdout=None, stderr=None, | |
|
251 | 252 | executable=None, independent=False): |
|
252 | 253 | """ Launches a localhost kernel, binding to the specified ports. |
|
253 | 254 | |
@@ -268,6 +269,9 b' def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
268 | 269 | hb_port : int, optional |
|
269 | 270 | The port to use for the hearbeat REP channel. |
|
270 | 271 | |
|
272 | stdin, stdout, stderr : optional (default None) | |
|
273 | Standards streams, as defined in subprocess.Popen. | |
|
274 | ||
|
271 | 275 | executable : str, optional (default sys.executable) |
|
272 | 276 | The Python executable to use for the kernel process. |
|
273 | 277 | |
@@ -291,8 +295,8 b' def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,' | |||
|
291 | 295 | |
|
292 | 296 | return base_launch_kernel('from IPython.zmq.pykernel import main; main()', |
|
293 | 297 | xrep_port, pub_port, req_port, hb_port, |
|
294 |
|
|
|
295 |
ex |
|
|
298 | stdin, stdout, stderr, | |
|
299 | executable, independent, extra_arguments) | |
|
296 | 300 | |
|
297 | 301 | main = make_default_main(Kernel) |
|
298 | 302 |
General Comments 0
You need to be logged in to leave comments.
Login now