Skip to content

Commit

Permalink
prevent reusing kernel IDs
Browse files Browse the repository at this point in the history
previous method of using tab count allowed collisions when closing and reopening tabs.
  • Loading branch information
minrk committed Oct 20, 2011
1 parent cfc7e4a commit 2059d0a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions IPython/frontend/qt/console/mainwindow.py
Expand Up @@ -63,6 +63,7 @@ def __init__(self, app,
"""

super(MainWindow, self).__init__()
self._kernel_counter = 0
self._app = app
self.confirm_exit = confirm_exit
self.new_frontend_factory = new_frontend_factory
Expand Down Expand Up @@ -96,6 +97,13 @@ def update_tab_bar_visibility(self):
if self.tab_widget.count()==0 :
self.close()

@property
def next_kernel_id(self):
"""constantly increasing counter for kernel IDs"""
c = self._kernel_counter
self._kernel_counter += 1
return c

@property
def active_frontend(self):
return self.tab_widget.currentWidget()
Expand All @@ -115,7 +123,7 @@ def create_tab_with_current_kernel(self):
# don't keep stacking slaves
name = current_widget_name
else:
name = str('('+current_widget_name+') slave')
name = '(%s) slave' % current_widget_name
self.add_tab_with_frontend(widget,name=name)

def close_tab(self,current_tab):
Expand Down Expand Up @@ -231,7 +239,7 @@ def add_tab_with_frontend(self,frontend,name=None):
"""
if not name:
name=str('kernel '+str(self.tab_widget.count()))
name = 'kernel %i' % self.next_kernel_id
self.tab_widget.addTab(frontend,name)
self.update_tab_bar_visibility()
self.make_frontend_visible(frontend)
Expand Down

0 comments on commit 2059d0a

Please sign in to comment.