【发布时间】:2012-11-27 05:57:10
【问题描述】:
我有一些通过 cron 运行的 python 脚本,当使用绝对路径调用脚本时它们不再正确退出。它们将挂起,直到进程终止。我相信这是在我将 /var 和 /home 移动到不同的分区之后发生的。
我检查了环境变量,没有发现任何明显错误,这在使用 cron 或 bash 子shell 运行时会发生,但在直接运行时不会发生。
如果我将它作为子 shell 运行,它会挂起,直到我杀死它 (ctrl-c) 然后给我输出。
[wotstats@rock test]$ echo 'assert 0==1, "fails"' > test.py
[wotstats@rock test]$ /bin/bash -c "/usr/bin/python /var/home/wotstats/test/test.py"
^CTraceback (most recent call last):
File "/var/home/wotstats/test/test.py", line 1, in <module>
assert 0==1, "fails"
AssertionError: fails
如果我不调用脚本,它会按预期终止而不会挂起:
[wotstats@rock test]$ /bin/bash -c "echo 'assert 0==1, \"fails\"' | /usr/bin/python"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError: fails
当异常发生时,我会立即收到日志错误:
Dec 9 13:33:44 rock abrt: detected unhandled Python exception in '/var/home/wotstats/test/test.py'
我根据输入运行了一些测试,发现即使以 /test.py 调用并以 root 身份运行时也会出现此问题。我也试过 /root 和 /usr 有同样的效果。
Similar or same question 在这里被询问并通过重启解决;如果可以的话,我宁愿弄清楚并避免重新启动。
【问题讨论】:
-
也许这是一个 bash 的东西而不是 python 的东西?尝试替换另一个 shell。
-
sh/csh/tcsh 具有相同的行为。
-
运行了一个 php 脚本,它立即死掉了。
-
好的,所以不是这样。很难想象移动 /var 和 home 有什么关系。
-
路径有关系吗?如果您的 /usr/bin/python 参数只是 test.py 而不是完整路径怎么办?
标签: python relative-path freeze absolute-path unhandled-exception