marcpezz:
from dockerspawner import DockerSpawner
c = get_config()
class DemoFormSpawner(DockerSpawner):
default_memo_lim = "1G"
def _options_form_default(self):
return """
<div class="form-group">
<label for="args">Extra notebook CLI arguments</label>
<input name="args" class="form-control"
placeholder="e.g. --debug"></input>
</div>
<div class="form-group">
<label for="memo_lim">Memory Limit:</label>
<input type="text" id="memo_lim" name="memo_lim"></input>
</div>
"""
def options_from_form(self, formdata):
self.log.debug("Executing options_from_form")
options = {}
options["memo_lim"] = formdata.get('memo_lim', [''])[0].strip()
self.log.debug("Parsed memory limit %s", options["memo_lim"])
arg_s = formdata.get('args', [''])[0].strip()
if arg_s:
options['argv'] = shlex.split(arg_s)
self.log.debug("Extra CLI Arguments: %s", options['argv'])
return options
def get_args(self):
"""Return arguments to pass to the notebook server"""
self.log.debug("User options are %s", self.user_options)
argv = super().get_args()
if self.user_options.get('argv'):
argv.extend(self.user_options['argv'])
return argv
def get_memo(self):
if self.user_options.get('memo_lim'):
return self.user_options['memo_lim']
return self.default_memo_lim
async def start(self):
self.log.debug("Current memory limit: %s", self.get_memo())
return super().start()
c.JupyterHub.spawner_class = DemoFormSpawner
Can you try with this snippet? I m not sure if it works, but config should be something like this.
In your config, you are instantiating an object out of spawner class and calling get_memo()
directly on it. You should provide just the class and it is JupyterHub’s responsibility to instantiate spawner object and call the methods properly to parse the options from form before spawning a single user server.