[Bug 1774843] [NEW] apport python exception handler messes up python3.7

Bart Goeman 1774843 at bugs.launchpad.net
Sun Jun 3 07:01:55 UTC 2018


Public bug reported:

it seems apport installs an exception hook whenever running python3.
This hook is apparently installed for python3.7 too.
This exception handler has a dependency on apt_pkg, which is a binary that is not compatible with python3.7 it seems (you can't import it, see below)

As a result, whenever I run a python3.7 script and run into an exception (which happens often when writing code), I get an additional exception in the exception handler + a copy of the original exception, so three stacktraces in total.
A solution would be to only install the exception hook for the system python  i.e. python3.6


$ lsb_release -rd
Description:	Ubuntu 18.04 LTS
Release:	18.04

apport: 2.20.9-0ubuntu7
python-apt: 1.6.0
python3.7: 3.7.0~b3-1

Demo with a trivial error:
$ python3 -c 'print hello'
  File "<string>", line 1
    print hello
              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(hello)?


$ python3.7 -c 'print hello'
  File "<string>", line 1
    print hello
              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(hello)?
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 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
  File "<string>", line 1
    print hello
              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(hello)?


Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.excepthook
<function apport_excepthook at 0x7fdf2b99a620>
>>> import apt_pkg
>>> apt_pkg.__file__
'/usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so'
>>> 

Python 3.7.0b3 (default, Mar 30 2018, 04:35:22) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.excepthook
<function apport_excepthook at 0x7f29a6eebea0>
>> import apt_pkg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'apt_pkg'

** Affects: apport (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to apport in Ubuntu.
https://bugs.launchpad.net/bugs/1774843

Title:
  apport python exception handler messes up python3.7

Status in apport package in Ubuntu:
  New

Bug description:
  it seems apport installs an exception hook whenever running python3.
  This hook is apparently installed for python3.7 too.
  This exception handler has a dependency on apt_pkg, which is a binary that is not compatible with python3.7 it seems (you can't import it, see below)

  As a result, whenever I run a python3.7 script and run into an exception (which happens often when writing code), I get an additional exception in the exception handler + a copy of the original exception, so three stacktraces in total.
  A solution would be to only install the exception hook for the system python  i.e. python3.6

  
  $ lsb_release -rd
  Description:	Ubuntu 18.04 LTS
  Release:	18.04

  apport: 2.20.9-0ubuntu7
  python-apt: 1.6.0
  python3.7: 3.7.0~b3-1

  Demo with a trivial error:
  $ python3 -c 'print hello'
    File "<string>", line 1
      print hello
                ^
  SyntaxError: Missing parentheses in call to 'print'. Did you mean print(hello)?

  
  $ python3.7 -c 'print hello'
    File "<string>", line 1
      print hello
                ^
  SyntaxError: Missing parentheses in call to 'print'. Did you mean print(hello)?
  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 24, in <module>
      import apt
    File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
      import apt_pkg
  ModuleNotFoundError: No module named 'apt_pkg'

  Original exception was:
    File "<string>", line 1
      print hello
                ^
  SyntaxError: Missing parentheses in call to 'print'. Did you mean print(hello)?


  Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
  [GCC 7.3.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> sys.excepthook
  <function apport_excepthook at 0x7fdf2b99a620>
  >>> import apt_pkg
  >>> apt_pkg.__file__
  '/usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so'
  >>> 

  Python 3.7.0b3 (default, Mar 30 2018, 04:35:22) 
  [GCC 7.3.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> sys.excepthook
  <function apport_excepthook at 0x7f29a6eebea0>
  >> import apt_pkg
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ModuleNotFoundError: No module named 'apt_pkg'

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1774843/+subscriptions



More information about the foundations-bugs mailing list