Skip to content

Commit 7d00686

Browse files
committed
restart with new random ports if kernel was never alive
1 parent b613012 commit 7d00686

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

jupyter_client/restarter.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class KernelRestarter(LoggingConfigurable):
3636
)
3737
_restarting = Bool(False)
3838
_restart_count = Integer(0)
39+
_initial_startup = Bool(True)
3940

4041
callbacks = Dict()
4142
def _callbacks_default(self):
@@ -98,14 +99,17 @@ def poll(self):
9899
self._restart_count = 0
99100
self.stop()
100101
else:
101-
self.log.info('KernelRestarter: restarting kernel (%i/%i)',
102+
self.log.info('KernelRestarter: restarting kernel (%i/%i), %s random ports',
102103
self._restart_count,
103-
self.restart_limit
104+
self.restart_limit,
105+
'new' if self._initial_startup else 'keep'
104106
)
105107
self._fire_callbacks('restart')
106-
self.kernel_manager.restart_kernel(now=True)
108+
self.kernel_manager.restart_kernel(now=True, newports=self._initial_startup)
107109
self._restarting = True
108110
else:
111+
if self._initial_startup:
112+
self._initial_startup = False
109113
if self._restarting:
110114
self.log.debug("KernelRestarter: restart apparently succeeded")
111115
self._restarting = False

0 commit comments

Comments
 (0)