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 May 22, 2018
1 parent dbadffb commit 1ad5ed5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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
31 changes: 31 additions & 0 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
"""
import pwd
import os
import sys

import xml.etree.ElementTree as ET

# 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 @@ -353,6 +360,28 @@ 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
@asyncio.coroutine
def progress(self):
while True:
if self.state_ispending():
yield_from_({
"message": "Pending in queue...",
})
elif self.state_isrunning():
yield_from_({
"message": "Cluster job running... waiting to connect",
})
return
else:
yield_from_({
"message": "Unknown status...",
})
yield_from_(gen.sleep(.1))

import re

class BatchSpawnerRegexStates(BatchSpawnerBase):
Expand Down Expand Up @@ -486,6 +515,8 @@ class SlurmSpawner(UserEnvMixin,BatchSpawnerRegexStates):
#SBATCH --get-user-env=L
#SBATCH {options}
sleep 30
which jupyterhub-singleuser
{cmd}
""").tag(config=True)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
async_generator>=1.8; python_version >= '3.5'
jupyterhub>=0.5

0 comments on commit 1ad5ed5

Please sign in to comment.