Skip to content

Commit

Permalink
Add progress indicators when spawning
Browse files Browse the repository at this point in the history
- Uses JupyterHub 0.9 feature, no effect for <0.9.
- Closes: #81
  • Loading branch information
rkdarst committed Jun 20, 2018
1 parent ecc8dd8 commit c13e4c2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ install:
- if [ $JHUB_VER != "master" -a $JHUB_VER != "0.9.0b2" ]; then pip install "tornado<5.0"; fi
- pip install --pre -f travis-wheels/wheelhouse -r jupyterhub/dev-requirements.txt
- pip install --pre -e jupyterhub
- pip install --pre -f travis-wheels/wheelhouse -r requirements.txt

script:
- travis_retry py.test --lf --cov batchspawner batchspawner/tests -v
Expand Down
28 changes: 28 additions & 0 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
"""
import pwd
import os
import sys

import xml.etree.ElementTree as ET

from jinja2 import Template

# For the progress method of JupyterHub 0.9, requiring Python 3.5+.
# If not supported, don't support it which is OK.
if sys.version_info >= (3, 5):
import asyncio
from async_generator import async_generator, yield_, yield_from_

from tornado import gen
from tornado.process import Subprocess
from subprocess import CalledProcessError
Expand Down Expand Up @@ -394,6 +401,27 @@ def stop(self, now=False):
self.job_id, self.current_ip, self.port)
)

# The progress method is only supported on JupyterHub 0.9, which
# only supports Python 3.5+. It requires asyncio coroutines.
if sys.version_info >= (3, 5):
@async_generator
async def progress(self):
while True:
if self.state_ispending():
await yield_({
"message": "Pending in queue...",
})
elif self.state_isrunning():
await yield_({
"message": "Cluster job running... waiting to connect",
})
return
else:
await yield_({
"message": "Unknown status...",
})
await gen.sleep(.1)

import re

class BatchSpawnerRegexStates(BatchSpawnerBase):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
async_generator>=1.8; python_version >= '3.5'
jinja2
jupyterhub>=0.5

0 comments on commit c13e4c2

Please sign in to comment.