python 3 exception also gives the output of the previous program

时间:2018-03-22 23:59:22

标签: python-3.x ubuntu

i ran into an interesting bug when writing a json parser(called /home/myusername/py/json.py) in python3 i raised a basic exception and got unexpected output,

when investigating this further i wrote a new script entirely given below

/home/myusername/py/error.py

raise Exception("basic exception")

after running "python3 error.py" i should get a really short error message, but instead i get console output of the previous run program.

[unexpected debug output of json.py]
[truncated for readability]
[it is extremely long but does not contain further errors]

Traceback (most recent call last):
File "error.py", line 1, in <module>
raise Exception("basic exception")
Exception: basic exception
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 17, in <module>
    import json
  File "/home/myusername/py/json.py", line 174, in <module>
    rs = parser.Object(testcase)
  File "/home/myusername/py/json.py", line 104, in Object
    raise Exception(self.Array(source, "crashing object scanner"))
Exception: None

Original exception was:
Traceback (most recent call last):
  File "error.py", line 1, in <module>
    raise Exception("basic exception")
Exception: basic exception

i dont know why i get such a long message. nor do i know why i get debug code of an uncalled script. i would like an explanation, i am running Ubuntu, i have not yet found related bugs on the internet.

1 个答案:

答案 0 :(得分:0)

基本的异常处理似乎需要一个json.py脚本,所以当我的error.py引发异常时,它会加载我的json.py脚本而不是buildin脚本,那么我的json脚本会出现异常。

解决方案是重命名我的json.py