Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow batchspawner to be used with different notebook singleuser cmd #141

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 18 additions & 14 deletions batchspawner/singleuser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from jupyterhub.singleuser import SingleUserNotebookApp
from jupyterhub.utils import random_port, url_path_join
from traitlets import default
import os
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.client_ca = os.environ.get('JUPYTERHUB_SSL_CLIENT_CA', '')
hub_auth.certfile = os.environ.get('JUPYTERHUB_SSL_CERTFILE', '')
hub_auth.keyfile = os.environ.get('JUPYTERHUB_SSL_KEYFILE', '')
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()