def start_restarter(self): if self.autorestart and self.has_kernel: if self._restarter is None: self._restarter = IOLoopKernelRestarter(kernel_manager=self, loop=self.loop, parent=self, log=self.log) self._restarter.start()
def start_restarter(self): if self.autorestart and self.has_kernel: if self._restarter is None: self._restarter = IOLoopKernelRestarter( kernel_manager=self, loop=self.loop, parent=self, log=self.log ) self._restarter.start()
class RemoteIOLoopKernelManager(KernelManager): loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False) # _restarter = Instance('remotekernel.restarter.RemoteIOLoopKernelRestarter') def _loop_default(self): return ioloop.IOLoop.instance() def start_kernel(self, **kw): """Starts a kernel on this host in a separate process. If random ports (port=0) are being used, this method must be called before the channels are created. Parameters ---------- **kw : optional keyword arguments that are passed down to build the kernel_cmd and launching the kernel (e.g. Popen kwargs). """ self.ip = socket.gethostbyname(self.kernel_spec.host) # write connection file / get default ports self.write_connection_file() # save kwargs for use in restart self._launch_args = kw.copy() # build the Popen cmd extra_arguments = kw.pop('extra_arguments', []) # build kernel_cmd; we will overwrite the connection_file arg below kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments) # debug stuff # This may be OSX only. It ensures passwordless login works. # decide where to copy the connection file on the remote host get_remote_home = Popen(['ssh', self.ip, 'echo', '$HOME'], stdin=PIPE, stdout=PIPE) if get_remote_home.wait() != 0: raise RuntimeError("Failed to connect to remote host {0}" "".format(self.ip)) result, = get_remote_home.stdout.readlines() remote_home = result.decode()[:-1] remote_connection_file = os.path.join( remote_home, '.ipython', 'kernels', os.path.basename(self.connection_file)) # copy the connection file to the remote machine remote_connection_file_dir = os.path.dirname(remote_connection_file) mkdirp = Popen(['ssh', self.ip, 'mkdir', '-p', remote_connection_file_dir]) if mkdirp.wait() != 0: raise RuntimeError("Failed to create directory for connection " "file on remote host {0}".format(self.ip)) transfer = Popen(['scp', self.connection_file, '{0}:{1}'.format(self.ip, remote_connection_file)]) if transfer.wait() != 0: raise RuntimeError("Failed to copy connection file to host {0}" "".format(self.ip)) # launch the kernel subprocess kernel_cmd[1 + kernel_cmd.index('-f')] = remote_connection_file # if len(kernel_cmd) > 6: # kernel_cmd[6] = remote_profile_dir = os.path.join(remote_connection_file_dir, '..', 'profile_default') kernel_cmd.append('--debug') self.kernel = Popen(['ssh', self.ip, '{0}'.format(' '.join(kernel_cmd))], stdout=PIPE, stdin=PIPE, env=os.environ) # self.start_restarter() self._connect_control_socket() _restarter = Instance('jupyter_client.ioloop.IOLoopKernelRestarter', allow_none=True) def start_restarter(self): if self.autorestart and self.has_kernel: if self._restarter is None: self._restarter = IOLoopKernelRestarter( kernel_manager=self, loop=self.loop, parent=self, log=self.log ) self._restarter.start() def stop_restarter(self): if self.autorestart: if self._restarter is not None: self._restarter.stop() connect_shell = as_zmqstream(KernelManager.connect_shell) connect_iopub = as_zmqstream(KernelManager.connect_iopub) connect_stdin = as_zmqstream(KernelManager.connect_stdin) connect_hb = as_zmqstream(KernelManager.connect_hb)
class RemoteIOLoopKernelManager(KernelManager): loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False) # _restarter = Instance('remotekernel.restarter.RemoteIOLoopKernelRestarter') def _loop_default(self): return ioloop.IOLoop.instance() def start_kernel(self, **kw): """Starts a kernel on this host in a separate process. If random ports (port=0) are being used, this method must be called before the channels are created. Parameters ---------- **kw : optional keyword arguments that are passed down to build the kernel_cmd and launching the kernel (e.g. Popen kwargs). """ self.ip = socket.gethostbyname(self.kernel_spec.host) # write connection file / get default ports self.write_connection_file() # save kwargs for use in restart self._launch_args = kw.copy() # build the Popen cmd extra_arguments = kw.pop('extra_arguments', []) # build kernel_cmd; we will overwrite the connection_file arg below kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments) # decide where to copy the connection file on the remote host try_ssh = Popen(['ssh', self.ip, 'exit'], stdin=PIPE, stdout=PIPE) stdout, stderr = try_ssh.communicate() if try_ssh.returncode != 0: raise RuntimeError("Failed to connect to remote host {0}. " "stdout: '{1}' stdin: '{2}'" "".format(self.ip, stdout, stderr)) remote_connection_file = os.path.join( '~', '.ipython', 'kernels', os.path.basename(self.connection_file)) # copy the connection file to the remote machine remote_connection_file_dir = os.path.dirname(remote_connection_file) mkdirp = Popen( ['ssh', self.ip, 'mkdir', '-p', remote_connection_file_dir]) stdout, stderr = mkdirp.communicate() if mkdirp.returncode != 0: raise RuntimeError("Failed to create directory for connection " "file at {0} on remote host {1}. " "stdout: '{2}' stdin: '{3}'" "".format(remote_connection_file_dir, self.ip, stdout, stderr)) transfer = Popen([ 'scp', self.connection_file, '{0}:{1}'.format(self.ip, remote_connection_file) ]) stdout, stderr = transfer.communicate() if transfer.returncode != 0: raise RuntimeError("Failed to copy connection file into directory " "{0} on remote host {1}. " "stdout: '{2}' stdin: '{3}'" "".format(remote_connection_file_dir, self.ip, stdout, stderr)) # launch the kernel subprocess kernel_cmd[1 + kernel_cmd.index('-f')] = remote_connection_file self.kernel = Popen( ['ssh', self.ip, '{0}'.format(' '.join(kernel_cmd))], stdout=PIPE, stdin=PIPE, env=os.environ) # self.start_restarter() self._connect_control_socket() _restarter = Instance('jupyter_client.ioloop.IOLoopKernelRestarter', allow_none=True) def start_restarter(self): if self.autorestart and self.has_kernel: if self._restarter is None: self._restarter = IOLoopKernelRestarter(kernel_manager=self, loop=self.loop, parent=self, log=self.log) self._restarter.start() def stop_restarter(self): if self.autorestart: if self._restarter is not None: self._restarter.stop() connect_shell = as_zmqstream(KernelManager.connect_shell) connect_iopub = as_zmqstream(KernelManager.connect_iopub) connect_stdin = as_zmqstream(KernelManager.connect_stdin) connect_hb = as_zmqstream(KernelManager.connect_hb)