从cron或subshel​​l用绝对路径调用Python时不会退出 [英] Python won't exit when called with absolute path from cron or subshell

查看:122
本文介绍了从cron或subshel​​l用绝对路径调用Python时不会退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些通过cron运行的python脚本,当使用绝对路径调用脚本时,它们不再正确退出.它们将挂起,直到该过程终止.我相信这是在将/var和/home移到另一个分区之后发生的.

I have some python scripts that run via cron, and they no longer exit correctly when the script is called with an absolute path. They will hang until the process is terminated. I believe it happened after I moved /var and /home to a different partition.

我检查了环境变量,没有发现任何明显错误,这是在使用cron或bash子shell运行时发生的,但是在直接运行时却没有发生.

I checked into the environment variables and couldn't see anything obviously wrong, this happens either when run with cron or a bash subshell, but not when run directly.

如果我将其作为子外壳程序运行,它将挂起,直到我将其杀死(ctrl-c),然后将输出显示给我.

If I run it as a subshell it hangs until I kill it (ctrl-c) and then gives me the output.

[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

如果我不调用脚本,它将按预期终止而不会挂起:

If I don't call a script it terminates as expected without hanging:

[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

发生异常时,我确实会立即收到日志错误:

I do get an immediate log error when the exception occurs:

Dec  9 13:33:44 rock abrt: detected unhandled Python exception in '/var/home/wotstats/test/test.py'

我根据输入进行了一些测试,发现即使以/test.py调用并以root身份运行时,也会出现此问题.我也尝试过/root和/usr具有相同的效果.

I ran some tests based on the input, and found that this problem occurs even when called as /test.py and when run as root. I also tried /root and /usr with the same effect.

类似或在此处提出了相同的问题,并通过重新启动进行了解决;我宁愿找出来,如果可以的话,请避免重新启动.

Similar or same question was asked here and resolved by reboot; I'd rather figure it out and avoid the reboot if I can.

推荐答案

好,知道了.感谢您的帮助.

Ok, got it figured out. Thanks for the help.

我跑了一条路,发现它挂在下面的东西上:

I ran an strace and found that it was hanging on the following:

socket(PF_FILE, SOCK_STREAM, 0)         = 4
connect(4, {sa_family=AF_FILE, path="/var/run/abrt/abrt.socket"}, 27^C
<unfinished ...>

这导致 Bugzilla 表示SELinux是问题所在.我已经将SELinux更改为许可模式(我将其固定在/var上),但没有重新启动abrtd.

That led to Bugzilla which indicated that SELinux was the problem. I had already changed SELinux to permissive mode (I screwed it up moving /var), but had not restarted abrtd.

重新启动abrtd服务可以解决该问题.

Restarting the abrtd service resolved the problem.

这篇关于从cron或subshel​​l用绝对路径调用Python时不会退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆