运行 从 launchd 运行 runipy
Running runipy from launchd
我正在尝试使用 运行ipy 和 osx 的 launchd 定期 运行 一个 jupyter notebook。
这在命令行中有效
/path/to/interpreter/python.3.4 /path/to/runipy/main.py /path/to/notebook/nb.ipynb
但是启动 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)
您在使用 LaunchControl 吗?我建议使用它,这样您就可以轻松地在控制台中捕获标准错误并查看底层异常代码 1。如果没有 LaunchControl,您还可以将这些键添加到 .plist:
<key>StandardErrorPath</key>
<string>/tmp/com.your.thing.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.your.thing.out</string>
我通过创建一个使用 runipy 的中间 py 文件并使用编码打开笔记本来绕过 "ascii" 错误="utf-8"
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>
我正在尝试使用 运行ipy 和 osx 的 launchd 定期 运行 一个 jupyter notebook。
这在命令行中有效
/path/to/interpreter/python.3.4 /path/to/runipy/main.py /path/to/notebook/nb.ipynb
但是启动 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)
您在使用 LaunchControl 吗?我建议使用它,这样您就可以轻松地在控制台中捕获标准错误并查看底层异常代码 1。如果没有 LaunchControl,您还可以将这些键添加到 .plist:
<key>StandardErrorPath</key>
<string>/tmp/com.your.thing.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.your.thing.out</string>
我通过创建一个使用 runipy 的中间 py 文件并使用编码打开笔记本来绕过 "ascii" 错误="utf-8"
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>