def __init__(self, popen, files_to_cleanup=None, win_interrupt_evt=None): self.kernel = popen self.files_to_cleanup = files_to_cleanup or [] self.win_interrupt_evt = win_interrupt_evt self.log = get_app_logger() self.kernel_id = str(uuid.uuid4()) # Capture subprocess kind from instance information self.async_subprocess = isinstance(popen, asyncio.subprocess.Process) if self.async_subprocess: self._exit_future = asyncio.ensure_future(self.kernel.wait())
def __init__(self, connection_info, manager=None, use_heartbeat=True): self.connection_info = connection_info self.messaging = ClientMessaging(connection_info) if (manager is None) and 'nanny_control_port' in connection_info: self.manager = ManagerClient(self.messaging, connection_info) else: self.manager = manager self.session = self.messaging.session self.log = get_app_logger()
def __init__(self, user_kernel_dir=None, kernel_dirs=None, kernel_file=DEFAULT_KERNEL_FILE): super().__init__() self.user_kernel_dir = user_kernel_dir or self._user_kernel_dir_default( ) if kernel_dirs is None: kernel_dirs = self._kernel_dirs_default() self.kernel_dirs = kernel_dirs self.kernel_file = kernel_file self.log = get_app_logger()
def __init__(self, kernel_cmd, cwd, extra_env=None, ip=None): self.kernel_cmd = kernel_cmd self.cwd = cwd self.extra_env = extra_env if ip is None: ip = localhost() self.ip = ip self.log = get_app_logger() if self.transport == 'tcp' and not is_local_ip(ip): raise RuntimeError( "Can only launch a kernel on a local interface. " "Make sure that the '*_address' attributes are " "configured properly. " "Currently valid addresses are: %s" % local_ips())
class RemoteKernelProviderBase(KernelSpecProvider): log = get_app_logger() # We should always be run within an application # The following must be overridden by subclasses id = None kernel_file = None lifecycle_manager_classes = [] def find_kernels(self): """Offers kernel types from installed kernelspec directories. Subclasses can perform optional pre and post checks surrounding call to superclass. """ return super(RemoteKernelProviderBase, self).find_kernels() def launch(self, kernelspec_name, cwd=None, kernel_params=None): """Launch a kernel, return (connection_info, kernel_manager). name will be one of the kernel names produced by find_kernels() This method launches and manages the kernel in a blocking manner. """ kernelspec = self.ksm.get_kernel_spec(kernelspec_name) lifecycle_info = self._get_lifecycle_info(kernelspec) # Make the appropriate application configuration (relative to provider) available during launch app_config = self._get_app_config() # Launch the kernel via the kernel manager class method, returning its connection information # and kernel manager. kwargs = dict() kwargs['kernelspec'] = kernelspec kwargs['lifecycle_info'] = lifecycle_info kwargs['cwd'] = cwd kwargs['kernel_params'] = kernel_params or {} kwargs['app_config'] = app_config return RemoteKernelManager.launch(**kwargs) def launch_async(self, name, cwd=None): pass def _get_app_config(self): """Pulls application configuration 'section' relative to current class.""" app_config = {} parent_app = Application.instance() if parent_app: # Collect config relative to our class instance. app_config = parent_app.config.get(self.__class__.__name__, {}).copy() return app_config def _get_lifecycle_info(self, kernel_spec): """Looks for the metadata stanza containing the process proxy information. This will be in the `process_proxy` stanza of the metadata. """ legacy_detected = False lifecycle_info = kernel_spec.metadata.get('lifecycle_manager', None) if lifecycle_info is None: lifecycle_info = kernel_spec.metadata.get('process_proxy', None) if lifecycle_info: legacy_detected = True if lifecycle_info: class_name = lifecycle_info.get('class_name', None) if class_name is not None: if class_name not in self.lifecycle_manager_classes: # Legacy check... legacy_detected = True lifecycle_info.update( {'class_name': self.lifecycle_manager_classes[0]}) if 'config' not in lifecycle_info: # if no config stanza, add one for consistency lifecycle_info.update({"config": {}}) if lifecycle_info is None: # Be sure to have a class_name with empty config lifecycle_info = { 'class_name': self.lifecycle_manager_classes[0], 'config': {} } if legacy_detected: self.log.warn( "Legacy kernelspec detected with at '{resource_dir}'. Ensure the contents of " "'{kernel_json}' contain a 'lifecycle_manager' stanza within 'metadata' with field " "class_name in '{expected_classes}'".format( resource_dir=kernel_spec.resource_dir, kernel_json=self.kernel_file, expected_classes=self.lifecycle_manager_classes)) return lifecycle_info
def __init__(self, popen, files_to_cleanup=None, win_interrupt_evt=None): self.kernel = popen self.files_to_cleanup = files_to_cleanup or [] self.win_interrupt_evt = win_interrupt_evt self.log = get_app_logger()