【问题标题】:Running runipy from launchd从 launchd 运行 runipy
【发布时间】:2016-03-10 21:57:00
【问题描述】:

我正在尝试利用 runipy 和 osx 的 launchd 定期运行 jupyter notebook。

这可以从命令行工作

/path/to/interpreter/python.3.4 /path/to/runipy/main.py /path/to/notebook/nb.ipynb

但是launchd plist 中的类似方法无法启动笔记本

<key>ProgramArguments</key>
<array>
    <string/path/to/interpreter/python.3.4</string>
    <string/path/to/runipy/main.py</string>
    <string/path/to/notebook/nb.ipynb</string>
</array>

当我检查控制台日志时,我只看到了这个神秘的错误

Service exited with abnormal code: 1

关于为什么失败的任何想法?

注意:我目前正在使用 launchd 在这台机器上使用类似的方法运行 py 文件。

更新:

根据 wij 的建议,我在 plist 中添加了以下几行

<key>StandardErrorPath</key>
<string>/tmp/com.your.thing.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.your.thing.out</string>

得到了

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3940: ordinal not in range(128)

【问题讨论】:

    标签: python macos launchd jupyter-notebook


    【解决方案1】:

    您在使用 LaunchControl 吗?我建议使用它,以便您可以轻松地在控制台中捕获标准错误并查看底层异常代码 1. 如果没有 LaunchControl,您还可以将这些键添加到 .plist:

    <key>StandardErrorPath</key>
    <string>/tmp/com.your.thing.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/com.your.thing.out</string>
    

    【讨论】:

    • 谢谢,我去看看
    【解决方案2】:

    我通过创建一个使用 runipy 并使用 encoding="utf-8" 打开笔记本的中间 py 文件解决了“ascii”错误

    nb_launcher.py

    from runipy.notebook_runner import NotebookRunner
    from IPython.nbformat.current import read
    
    notebook = read(open("nb.ipynb", encoding="utf-8"), 4)
    r = NotebookRunner(notebook)
    r.run_notebook()
    

    并从 launchd 调用它

    <key>ProgramArguments</key>
    <array>
        <string/path/to/interpreter/python.3.4</string>
        <string/path/to/py_file/nb_launcher.py</string>
    </array>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 2019-11-15
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多