diff --git a/.travis.yml b/.travis.yml index 4e8e1bf9..d4596de3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/batchspawner/batchspawner.py b/batchspawner/batchspawner.py index ac2a68f9..597b0167 100644 --- a/batchspawner/batchspawner.py +++ b/batchspawner/batchspawner.py @@ -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 @@ -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): diff --git a/requirements.txt b/requirements.txt index ee0a79e1..e7d37df9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ +async_generator>=1.8; python_version >= '3.5' jinja2 jupyterhub>=0.5