Skip to content

Commit

Permalink
Allow batchspawner to be used with different notebook app
Browse files Browse the repository at this point in the history
Instead of creating a batchspawner notebook app, batchspawner-singleuser
is now a wrapper that finds a port and add the port number to the
command-line argument of the singleuser app. This allows the usage
of batchspawner with jupyterlab for example.
  • Loading branch information
cmd-ntrf committed Apr 24, 2019
1 parent 383e8a3 commit a5e55bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
5 changes: 1 addition & 4 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class BatchSpawnerBase(Spawner):
state_gethost
"""

# override default since will need to set the listening port using the api
cmd = Command(['batchspawner-singleuser'], allow_none=True).tag(config=True)

# override default since batch systems typically need longer
start_timeout = Integer(300).tag(config=True)

Expand Down Expand Up @@ -190,7 +187,7 @@ def parse_job_id(self, output):
return output

def cmd_formatted_for_batch(self):
return ' '.join(self.cmd + self.get_args())
return ' '.join(['batchspawner-singleuser'] + self.cmd + self.get_args())

@gen.coroutine
def run_command(self, cmd, input=None, env=None):
Expand Down
28 changes: 14 additions & 14 deletions batchspawner/singleuser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from jupyterhub.singleuser import SingleUserNotebookApp
from jupyterhub.utils import random_port, url_path_join
from traitlets import default
import sys

class BatchSingleUserNotebookApp(SingleUserNotebookApp):
@default('port')
def _port(self):
return random_port()
from runpy import run_path
from shutil import which

def start(self):
# Send Notebook app's port number to remote Spawner
self.hub_auth._api_request(method='POST',
url=url_path_join(self.hub_api_url, 'batchspawner'),
json={'port' : self.port})
super().start()
from jupyterhub.utils import random_port, url_path_join
from jupyterhub.services.auth import HubAuth

def main(argv=None):
return BatchSingleUserNotebookApp.launch_instance(argv)
port = random_port()
hub_auth = HubAuth()
hub_auth._api_request(method='POST',
url=url_path_join(hub_auth.api_url, 'batchspawner'),
json={'port' : port})

cmd_path = which(sys.argv[1])
sys.argv = sys.argv[1:] + ['--port={}'.format(port)]
run_path(cmd_path, run_name="__main__")

if __name__ == "__main__":
main()

0 comments on commit a5e55bb

Please sign in to comment.