Skip to content

Commit 28a7207

Browse files
author
William Krinsman
committed
Made start, stop, poll asyncio coroutines too.
1 parent 207c602 commit 28a7207

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

batchspawner/batchspawner.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,10 @@ def state_gethost(self):
299299
"Return string, hostname or addr of running job, likely by parsing self.job_status"
300300
raise NotImplementedError("Subclass must provide implementation")
301301

302-
@gen.coroutine
303-
def poll(self):
302+
async def poll(self):
304303
"""Poll the process"""
305304
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()
307306
if self.state_isrunning() or self.state_ispending():
308307
return None
309308
else:
@@ -319,8 +318,7 @@ def poll(self):
319318
help="Polling interval (seconds) to check job state during startup"
320319
).tag(config=True)
321320

322-
@gen.coroutine
323-
def start(self):
321+
async def start(self):
324322
"""Start the process"""
325323
if self.user and self.user.server and self.user.server.port:
326324
self.port = self.user.server.port
@@ -329,15 +327,15 @@ def start(self):
329327
(jupyterhub.version_info >= (0,7) and not self.port):
330328
self.port = random_port()
331329
self.db.commit()
332-
job = yield self.submit_batch_script()
330+
job = await self.submit_batch_script()
333331

334332
# We are called with a timeout, and if the timeout expires this function will
335333
# be interrupted at the next yield, and self.stop() will be called.
336334
# So this function should not return unless successful, and if unsuccessful
337335
# should either raise and Exception or loop forever.
338336
assert len(self.job_id) > 0
339337
while True:
340-
yield self.poll()
338+
await self.poll()
341339
if self.state_isrunning():
342340
break
343341
else:
@@ -347,7 +345,7 @@ def start(self):
347345
self.log.warn('Job ' + self.job_id + ' neither pending nor running.\n' +
348346
self.job_status)
349347
assert self.state_ispending()
350-
yield gen.sleep(self.startup_poll_interval)
348+
await gen.sleep(self.startup_poll_interval)
351349

352350
self.current_ip = self.state_gethost()
353351
if jupyterhub.version_info < (0,7):
@@ -361,22 +359,21 @@ def start(self):
361359

362360
return self.current_ip, self.port
363361

364-
@gen.coroutine
365-
def stop(self, now=False):
362+
async def stop(self, now=False):
366363
"""Stop the singleuser server job.
367364
368365
Returns immediately after sending job cancellation command if now=True, otherwise
369366
tries to confirm that job is no longer running."""
370367

371368
self.log.info("Stopping server job " + self.job_id)
372-
yield self.cancel_batch_job()
369+
await self.cancel_batch_job()
373370
if now:
374371
return
375372
for i in range(10):
376-
yield self.poll()
373+
await self.poll()
377374
if not self.state_isrunning():
378375
return
379-
yield gen.sleep(1.0)
376+
await gen.sleep(1.0)
380377
if self.job_id:
381378
self.log.warn("Notebook server job {0} at {1}:{2} possibly failed to terminate".format(
382379
self.job_id, self.current_ip, self.port)

0 commit comments

Comments
 (0)