为什么当使用绝对路径执行Python时,Python不会从引发的异常中退出? [英] Why doesn't Python exit from a raised exception when executed with an absolute path?

查看:464
本文介绍了为什么当使用绝对路径执行Python时,Python不会从引发的异常中退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案:重新启动机器似乎已经删除了问题。我会更新,如果问题返回。



我有一个问题,其中 Python2.6 挂起一个例外特别是当 foo.py 以绝对路径调用( /home/user/bar/foo.py )。然后,我需要 ctrl + c 出程序。如果从 bar 目录中以 ./ foo.py 或从根目录为

foo.py:

 #!/ usr / bin / env python2.6 
print'begin'
x = [0,1,undefined]
print'x'

 #!/ usr / bin / env python2.6 
print'begin'
raise异常('stop here')

我也可以提到一个 sys.exit()没问题。

 #!/ usr / bin / env python2.6 
import sys
print'begin'
sys.exit(0)

正在发生的无法终止的异常发生了什么该程序?这可能是我的配置。我应该从哪里开始寻找解决方案?



编辑: execfile('/ home / user / bar / foo.py')如果运行交互模式工作正常。此外,运行 nohup /home/user/bar/foo.py& 导致挂起的进程必须被杀死。



运行CentOS版本6.3(最终)。这个问题并不总是存在。这只是在一个多月前在一个周末开始的(当时我没有使用机器)。



更新:使用GDB进行调试时,回溯指向 libpthread.so.0

 #0 0x000000364340e890在__connect_nocancel()从/lib64/libpthread.so.0 
#1 0x00007ffff18960d8 in ?? ()从/usr/lib64/python2.6/lib-dynload/_socketmodule.so
#2 0x00007ffff189815c在?? ()来自/usr/lib64/python2.6/lib-dynload/_socketmodule.so
#3 0xEFF_EvalFrameEx()中的0x00007ffff7d0a706来自/usr/lib64/libpython2.6.so.1.0
#4 0x00007ffff7d0c797来自/usr/lib64/libpython2.6.so.1.0中的/usr/lib64/libpython2.6.so.1.0
#5中的PyEval_EvalFrameEx()中的PyEval_EvalCodeEx()在PyEval_EvalFrameEx中的
#6 0x00007ffff7d0bccf ()from /usr/lib64/libpython2.6.so.1.0
#7 0xEFF_EvalFrameEx()中0xEFF_EvalFrameEx()中的/usr/lib64/libpython2.6.so.1.0
#8 PyEval_EvalCodeEx()中的0x00007ffff7d0c797从/usr/lib64/libpython2.6.so.1.0
#9 0x00007ffff7c9adb0在?? ()from /usr/lib64/libpython2.6.so.1.0
#10 0x8007ffff7c70303在Pyus_Call()从/usr/lib64/libpython2.6.so.1.0
#来自/usr/lib64/libpython2.6.so.1.0
#12 0x00007ffff7d28cd2在Pyrr_PrintEx()从/usr/lib64/libpython2.6.so.1.0
#13 0x00007ffff7d29297在PyRun_SimpleFileExFlags()从/来自/usr/lib64/libpython2.6.so.1.0
#15 0x000000364281ecdd在__libc_start_main()从/ lib64 / lib64 / libpython2.6.so.1.0
#14 0x8007ffff7d35c32 libc.so.6
#16 0x0000000000400649 in _start()

有人知道这是什么意思?

解决方案


  • 重新启动机器



向全能管理员致敬,我能够重新启动机器。一切都很好。如果问题返回,我会更新问题。


SOLVED: Rebooting the machine appears to have removed the issue. I will update if the problem returns.

I'm having an issue where Python2.6 hangs after an exception is raised, specifically when foo.py is called with an absolute path (/home/user/bar/foo.py). I am then required to ctrl+c out of the program. If called from within the bar directory as ./foo.py or from the root directory as ./home/user/bar/foo.py, the program terminates correctly.

foo.py:

#!/usr/bin/env python2.6
print 'begin'
x = [0, 1, undefined]
print 'x'

or

#!/usr/bin/env python2.6
print 'begin'
raise Exception('stopping here')

I may also mention that a sys.exit() works fine, without issues.

#!/usr/bin/env python2.6
import sys
print 'begin'
sys.exit(0)

What is happening to the exception that is failing to terminate the program? This is likely specific to my configuration. Where should I begin looking for a solution?

EDIT: execfile('/home/user/bar/foo.py') works fine if running interactive mode. Additionally, running nohup /home/user/bar/foo.py & results in a hanging process that must be killed.

Running CentOS release 6.3 (Final). This issue did not always exist. This only started about a month ago over a weekend (I was not using the machine at that time).

UPDATE: Debugging with GDB, the backtrace points to libpthread.so.0.

#0  0x000000364340e890 in __connect_nocancel () from /lib64/libpthread.so.0
#1  0x00007ffff18960d8 in ?? () from /usr/lib64/python2.6/lib-dynload/_socketmodule.so
#2  0x00007ffff189815c in ?? () from /usr/lib64/python2.6/lib-dynload/_socketmodule.so
#3  0x00007ffff7d0a706 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.6.so.1.0
#4  0x00007ffff7d0c797 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.6.so.1.0
#5  0x00007ffff7d0abe4 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.6.so.1.0
#6  0x00007ffff7d0bccf in PyEval_EvalFrameEx () from /usr/lib64/libpython2.6.so.1.0
#7  0x00007ffff7d0bccf in PyEval_EvalFrameEx () from /usr/lib64/libpython2.6.so.1.0
#8  0x00007ffff7d0c797 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.6.so.1.0
#9  0x00007ffff7c9adb0 in ?? () from /usr/lib64/libpython2.6.so.1.0
#10 0x00007ffff7c70303 in PyObject_Call () from /usr/lib64/libpython2.6.so.1.0
#11 0x00007ffff7d04dd3 in PyEval_CallObjectWithKeywords () from /usr/lib64/libpython2.6.so.1.0
#12 0x00007ffff7d28cd2 in PyErr_PrintEx () from /usr/lib64/libpython2.6.so.1.0
#13 0x00007ffff7d29297 in PyRun_SimpleFileExFlags () from /usr/lib64/libpython2.6.so.1.0
#14 0x00007ffff7d35c32 in Py_Main () from /usr/lib64/libpython2.6.so.1.0
#15 0x000000364281ecdd in __libc_start_main () from /lib64/libc.so.6
#16 0x0000000000400649 in _start ()

Anybody know what this means?

解决方案

  • Reboot the machine.

Bowing to the graces of the all-powerful admin, I was able to get the machine rebooted. All is well. I'll update the question if the problem returns.

这篇关于为什么当使用绝对路径执行Python时,Python不会从引发的异常中退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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