29
29
from tornado .iostream import StreamClosedError
30
30
31
31
from jupyterhub .spawner import Spawner
32
+ from jupyterhub .traitlets import Command
32
33
from traitlets import (
33
34
Integer , Unicode , Float , Dict , default
34
35
)
@@ -73,6 +74,9 @@ class BatchSpawnerBase(Spawner):
73
74
state_gethost
74
75
"""
75
76
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
+
76
80
# override default since batch systems typically need longer
77
81
start_timeout = Integer (300 ).tag (config = True )
78
82
@@ -164,6 +168,9 @@ def _req_keepvars_default(self):
164
168
# Will get the address of the server as reported by job manager
165
169
current_ip = Unicode ()
166
170
171
+ # Will get the port of the server as reported by singleserver
172
+ current_port = Integer ()
173
+
167
174
# Prepare substitution variables for templates using req_xyz traits
168
175
def get_req_subvars (self ):
169
176
reqlist = [ t for t in self .trait_names () if t .startswith ('req_' ) ]
@@ -342,14 +349,9 @@ def poll(self):
342
349
@gen .coroutine
343
350
def start (self ):
344
351
"""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 ()
352
+ if jupyterhub .version_info >= (0 ,8 ) and self .server :
353
+ self .server .port = self .port
354
+
353
355
job = yield self .submit_batch_script ()
354
356
355
357
# We are called with a timeout, and if the timeout expires this function will
@@ -374,16 +376,19 @@ def start(self):
374
376
yield gen .sleep (self .startup_poll_interval )
375
377
376
378
self .current_ip = self .state_gethost ()
379
+ while self .current_port == 0 :
380
+ yield gen .sleep (self .startup_poll_interval )
381
+
377
382
if jupyterhub .version_info < (0 ,7 ):
378
383
# store on user for pre-jupyterhub-0.7:
379
- self .user .server .port = self .port
384
+ self .user .server .port = self .current_port
380
385
self .user .server .ip = self .current_ip
381
386
self .db .commit ()
382
387
self .log .info ("Notebook server job {0} started at {1}:{2}" .format (
383
- self .job_id , self .current_ip , self .port )
388
+ self .job_id , self .current_ip , self .current_port )
384
389
)
385
390
386
- return self .current_ip , self .port
391
+ return self .current_ip , self .current_port
387
392
388
393
@gen .coroutine
389
394
def stop (self , now = False ):
0 commit comments