-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow batchspawner to be used with different notebook app
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
Showing
2 changed files
with
15 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |