Skip to content

Commit 37360e7

Browse files
committed
Merge remote-tracking branch 'upstream/pr/141' into dev
2 parents c80ed1f + e6d4bfa commit 37360e7

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

batchspawner/batchspawner.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ class BatchSpawnerBase(Spawner):
7474
state_gethost
7575
"""
7676

77-
# override default since will need to set the listening port using the api
78-
cmd = Command(['batchspawner-singleuser'], allow_none=True).tag(config=True)
79-
8077
# override default since batch systems typically need longer
8178
start_timeout = Integer(300).tag(config=True)
8279

@@ -184,7 +181,7 @@ def parse_job_id(self, output):
184181
return output
185182

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

189186
@gen.coroutine
190187
def run_command(self, cmd, input=None, env=None):

batchspawner/singleuser.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
from jupyterhub.singleuser import SingleUserNotebookApp
2-
from jupyterhub.utils import random_port, url_path_join
3-
from traitlets import default
1+
import os
2+
import sys
43

5-
class BatchSingleUserNotebookApp(SingleUserNotebookApp):
6-
@default('port')
7-
def _port(self):
8-
return random_port()
4+
from runpy import run_path
5+
from shutil import which
96

10-
def start(self):
11-
# Send Notebook app's port number to remote Spawner
12-
self.hub_auth._api_request(method='POST',
13-
url=url_path_join(self.hub_api_url, 'batchspawner'),
14-
json={'port' : self.port})
15-
super().start()
7+
from jupyterhub.utils import random_port, url_path_join
8+
from jupyterhub.services.auth import HubAuth
169

1710
def main(argv=None):
18-
return BatchSingleUserNotebookApp.launch_instance(argv)
11+
port = random_port()
12+
hub_auth = HubAuth()
13+
hub_auth.client_ca = os.environ.get('JUPYTERHUB_SSL_CLIENT_CA', '')
14+
hub_auth.certfile = os.environ.get('JUPYTERHUB_SSL_CERTFILE', '')
15+
hub_auth.keyfile = os.environ.get('JUPYTERHUB_SSL_KEYFILE', '')
16+
hub_auth._api_request(method='POST',
17+
url=url_path_join(hub_auth.api_url, 'batchspawner'),
18+
json={'port' : port})
19+
20+
cmd_path = which(sys.argv[1])
21+
sys.argv = sys.argv[1:] + ['--port={}'.format(port)]
22+
run_path(cmd_path, run_name="__main__")
1923

2024
if __name__ == "__main__":
2125
main()

0 commit comments

Comments
 (0)