【问题标题】:JupyterHub populate user home with notebooks (and data)JupyterHub 使用笔记本(和数据)填充用户主页
【发布时间】:2022-01-13 14:06:29
【问题描述】:

我有一个JupyterHub 服务器托管在 Ubuntu 机器上。

(主要)因为我想避免将数百个潜在用户添加到我选择使用c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'(带密码)的机器上

我使用的 Spawner 是 c.JupyterHub.spawner_class = 'jupyterhub.spawner.SimpleLocalProcessSpawner' 虽然我也试过'jupyterhub.spawner.LocalProcessSpawner'

我希望用户在登录后拥有一些预填充的笔记本

我第一次尝试https://tljh.jupyter.org/en/latest/howto/content/share-data.html将数据放入/etc/skel,但没有复制。

然后,根据各种文档,我可以设置c.Spawner.pre_spawn_hook = populate_user_home(也尝试过c.SimpleLocalProcessSpawner.pre_spawn_hook = populate_user_home)并让该方法将我想要的文件复制到用户家中。

我的方法看起来像:

def populate_user_home(spawner):
    username = spawner.user.name
    # DummyAuthenticator creates users in /tmp
    volume_path = os.path.join('/tmp', username)
    if not os.path.exists(volume_path):
        os.mkdir(volume_path, 0o777)
        copyDirectory(<path_to_tutorials>, os.path.join(volume_path, 'tutorials'))

问题是这个方法从未被调用过!

  1. 我做错了什么?
  2. 是否有另一种(更简单的?)方法来填充新用户的家?

【问题讨论】:

    标签: jupyter jupyterhub


    【解决方案1】:

    问题不是pre_spawn_hook,而是其他几个小问题。

    1. 在钩子代码中调用print 不会到达日志。方法被调用。
    2. 显然SimpleLocalProcessSpawner 在调用钩子之前创建了用户文件夹,因此从未调用过副本
    3. os.mkdir 实际上导致 copytree 失败,因为 dest 文件夹存在

    【讨论】:

      猜你喜欢
      • 2020-01-03
      • 2019-12-14
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-30
      相关资源
      最近更新 更多