Skip to content

Commit 41dc025

Browse files
committed
make restarter behavior configurable, default is to keep random ports
1 parent 7d00686 commit 41dc025

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

jupyter_client/restarter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class KernelRestarter(LoggingConfigurable):
3434
restart_limit = Integer(5, config=True,
3535
help="""The number of consecutive autorestarts before the kernel is presumed dead."""
3636
)
37+
38+
random_ports_until_alive = Bool(False, config=True,
39+
help="""Whether to choose new random ports when restarting before the kernel is alive."""
40+
)
3741
_restarting = Bool(False)
3842
_restart_count = Integer(0)
3943
_initial_startup = Bool(True)
@@ -99,13 +103,14 @@ def poll(self):
99103
self._restart_count = 0
100104
self.stop()
101105
else:
106+
newports = self.random_ports_until_alive and self._initial_startup
102107
self.log.info('KernelRestarter: restarting kernel (%i/%i), %s random ports',
103108
self._restart_count,
104109
self.restart_limit,
105-
'new' if self._initial_startup else 'keep'
110+
'new' if newports else 'keep'
106111
)
107112
self._fire_callbacks('restart')
108-
self.kernel_manager.restart_kernel(now=True, newports=self._initial_startup)
113+
self.kernel_manager.restart_kernel(now=True, newports=newports)
109114
self._restarting = True
110115
else:
111116
if self._initial_startup:

0 commit comments

Comments
 (0)