2929from tornado .iostream import StreamClosedError
3030
3131from jupyterhub .spawner import Spawner
32+ from jupyterhub .traitlets import Command
3233from traitlets import (
3334 Integer , Unicode , Float , Dict , default
3435)
@@ -73,6 +74,9 @@ class BatchSpawnerBase(Spawner):
7374 state_gethost
7475 """
7576
77+ # override default since will need to set the listening port using the api
78+ cmd = Command (['batchspawner-singleuser' ], allow_none = True ).tag (config = True )
79+
7680 # override default since batch systems typically need longer
7781 start_timeout = Integer (300 ).tag (config = True )
7882
@@ -342,14 +346,7 @@ def poll(self):
342346 @gen .coroutine
343347 def start (self ):
344348 """Start the process"""
345- if self .user and self .user .server and self .user .server .port :
346- self .port = self .user .server .port
347- self .db .commit ()
348- elif (jupyterhub .version_info < (0 ,7 ) and not self .user .server .port ) or (
349- jupyterhub .version_info >= (0 ,7 ) and not self .port
350- ):
351- self .port = random_port ()
352- self .db .commit ()
349+ self .port = self .server .port = 0
353350 job = yield self .submit_batch_script ()
354351
355352 # We are called with a timeout, and if the timeout expires this function will
@@ -374,6 +371,9 @@ def start(self):
374371 yield gen .sleep (self .startup_poll_interval )
375372
376373 self .current_ip = self .state_gethost ()
374+ while self .port == 0 :
375+ yield gen .sleep (self .startup_poll_interval )
376+
377377 if jupyterhub .version_info < (0 ,7 ):
378378 # store on user for pre-jupyterhub-0.7:
379379 self .user .server .port = self .port
0 commit comments