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