From 0d95952550b6c61922f15ea7842e5b2937a9d47c 2014-10-05 09:45:58
From: Matthias Bussonnier <bussonniermatthias@gmail.com>
Date: 2014-10-05 09:45:58
Subject: [PATCH] Merge pull request #6607 from minrk/cluster-load-remove

remove deleted profiles from cluster list
---

diff --git a/IPython/html/services/clusters/clustermanager.py b/IPython/html/services/clusters/clustermanager.py
index b159fc2..c0a8776 100644
--- a/IPython/html/services/clusters/clustermanager.py
+++ b/IPython/html/services/clusters/clustermanager.py
@@ -1,20 +1,7 @@
-"""Manage IPython.parallel clusters in the notebook.
+"""Manage IPython.parallel clusters in the notebook."""
 
-Authors:
-
-* Brian Granger
-"""
-
-#-----------------------------------------------------------------------------
-#  Copyright (C) 2008-2011  The IPython Development Team
-#
-#  Distributed under the terms of the BSD License.  The full license is in
-#  the file COPYING, distributed as part of this software.
-#-----------------------------------------------------------------------------
-
-#-----------------------------------------------------------------------------
-# Imports
-#-----------------------------------------------------------------------------
+# Copyright (c) IPython Development Team.
+# Distributed under the terms of the Modified BSD License.
 
 from tornado import web
 
@@ -26,13 +13,6 @@ from IPython.utils import py3compat
 from IPython.utils.path import get_ipython_dir
 
 
-#-----------------------------------------------------------------------------
-# Classes
-#-----------------------------------------------------------------------------
-
-
-
-
 class ClusterManager(LoggingConfigurable):
 
     profiles = Dict()
@@ -74,16 +54,24 @@ class ClusterManager(LoggingConfigurable):
     def update_profiles(self):
         """List all profiles in the ipython_dir and cwd.
         """
+        
+        stale = set(self.profiles)
         for path in [get_ipython_dir(), py3compat.getcwd()]:
             for profile in list_profiles_in(path):
+                if profile in stale:
+                    stale.remove(profile)
                 pd = self.get_profile_dir(profile, path)
                 if profile not in self.profiles:
-                    self.log.debug("Adding cluster profile '%s'" % profile)
+                    self.log.debug("Adding cluster profile '%s'", profile)
                     self.profiles[profile] = {
                         'profile': profile,
                         'profile_dir': pd,
                         'status': 'stopped'
                     }
+        for profile in stale:
+            # remove profiles that no longer exist
+            self.log.debug("Profile '%s' no longer exists", profile)
+            self.profiles.pop(stale)
 
     def list_profiles(self):
         self.update_profiles()