@@ -299,11 +299,10 @@ def state_gethost(self):
299
299
"Return string, hostname or addr of running job, likely by parsing self.job_status"
300
300
raise NotImplementedError ("Subclass must provide implementation" )
301
301
302
- @gen .coroutine
303
- def poll (self ):
302
+ async def poll (self ):
304
303
"""Poll the process"""
305
304
if self .job_id is not None and len (self .job_id ) > 0 :
306
- yield self .read_job_state ()
305
+ await self .read_job_state ()
307
306
if self .state_isrunning () or self .state_ispending ():
308
307
return None
309
308
else :
@@ -319,8 +318,7 @@ def poll(self):
319
318
help = "Polling interval (seconds) to check job state during startup"
320
319
).tag (config = True )
321
320
322
- @gen .coroutine
323
- def start (self ):
321
+ async def start (self ):
324
322
"""Start the process"""
325
323
if self .user and self .user .server and self .user .server .port :
326
324
self .port = self .user .server .port
@@ -329,15 +327,15 @@ def start(self):
329
327
(jupyterhub .version_info >= (0 ,7 ) and not self .port ):
330
328
self .port = random_port ()
331
329
self .db .commit ()
332
- job = yield self .submit_batch_script ()
330
+ job = await self .submit_batch_script ()
333
331
334
332
# We are called with a timeout, and if the timeout expires this function will
335
333
# be interrupted at the next yield, and self.stop() will be called.
336
334
# So this function should not return unless successful, and if unsuccessful
337
335
# should either raise and Exception or loop forever.
338
336
assert len (self .job_id ) > 0
339
337
while True :
340
- yield self .poll ()
338
+ await self .poll ()
341
339
if self .state_isrunning ():
342
340
break
343
341
else :
@@ -347,7 +345,7 @@ def start(self):
347
345
self .log .warn ('Job ' + self .job_id + ' neither pending nor running.\n ' +
348
346
self .job_status )
349
347
assert self .state_ispending ()
350
- yield gen .sleep (self .startup_poll_interval )
348
+ await gen .sleep (self .startup_poll_interval )
351
349
352
350
self .current_ip = self .state_gethost ()
353
351
if jupyterhub .version_info < (0 ,7 ):
@@ -361,22 +359,21 @@ def start(self):
361
359
362
360
return self .current_ip , self .port
363
361
364
- @gen .coroutine
365
- def stop (self , now = False ):
362
+ async def stop (self , now = False ):
366
363
"""Stop the singleuser server job.
367
364
368
365
Returns immediately after sending job cancellation command if now=True, otherwise
369
366
tries to confirm that job is no longer running."""
370
367
371
368
self .log .info ("Stopping server job " + self .job_id )
372
- yield self .cancel_batch_job ()
369
+ await self .cancel_batch_job ()
373
370
if now :
374
371
return
375
372
for i in range (10 ):
376
- yield self .poll ()
373
+ await self .poll ()
377
374
if not self .state_isrunning ():
378
375
return
379
- yield gen .sleep (1.0 )
376
+ await gen .sleep (1.0 )
380
377
if self .job_id :
381
378
self .log .warn ("Notebook server job {0} at {1}:{2} possibly failed to terminate" .format (
382
379
self .job_id , self .current_ip , self .port )
0 commit comments