abundant-hospital-56388
06/14/2022, 4:20 PM./pants run
command as well as in ./pants repl
.
I'm running it on my local Ubuntu 22.04 machine where apparently the sys.excepthook
is replaced by some apport_excepthook
. Trio tries to deal with that, but needs to import apport_python_hook
which seems to not exist in the pants environment.
I'm wondering how the environment that the ./pants run
and ./pants repl
command are working in is set up.
It seems to be somewhere between venv and running the system python natively as follows:
• it is not able to import apport_python_hook
which is available when running python3.10 on my system directly, but not in a venv.
• when checking sys.excepthook.__name__
that is set to apport_excepthook
, same as when running python directly on the system, but not in venv.abundant-hospital-56388
06/14/2022, 4:20 PMpython3.10
and then in there call
import sys
print(sys.excepthook.__name__)
import apport_python_hook
• Create a venv from python3.10 and run the same things in there
• Create the following pants.toml and pants file and run ./pants repl
and the same things in there
[GLOBAL]
pants_version = "2.11.0"
backend_packages = [
"pants.backend.python",
]
[python]
interpreter_constraints = ["CPython>=3.10,<4"]
The results should be as described above.
This seems to be a bit inconsistent, as I assume apport_python_hook
should be available for import if sys.excepthook
is set to use apport_excepthook
.happy-kitchen-89482
06/14/2022, 4:59 PMhappy-kitchen-89482
06/14/2022, 5:20 PMexcepthook
as the sys.excepthook.__name__
and apport_python_hook
is not availablehappy-kitchen-89482
06/14/2022, 5:20 PMapport
was installedwitty-crayon-22786
06/14/2022, 6:38 PMwitty-crayon-22786
06/14/2022, 6:39 PMwitty-crayon-22786
06/14/2022, 6:39 PMhappy-kitchen-89482
06/14/2022, 9:01 PMapt install python3-apport
abundant-hospital-56388
06/14/2022, 9:29 PMhappy-kitchen-89482
06/14/2022, 10:00 PMabundant-hospital-56388
06/15/2022, 9:31 AM/usr/bin
.
I also see now, why in the docker container this is not the case. Apparently python3-apport is installed as a dependency of ubuntu-desktop or ubuntu-desktop-minimal as both will be removed when I run apt remove python3-apport
. The docker container however does not come with a desktop environment so it's probably not installed there.
I actually really like to be able to use the system Python3 on Ubuntu and I don't want all devs to have to install an additional interpreter when that one is actually working fine for all other purposes.
Also uninstalling python3-apport
is not really an option.
As a workaround one can add
import sys
sys.excepthook = sys.__excepthook__
before any other imports in the binaries, but we have quite a few so that's a bit tedious.
@happy-kitchen-89482 do you think it might then be an option to address this with pex as it seems to not be aggressive enough in this case and should probably also reset the sys.excepthook
to sys.__excepthook__
🤔abundant-hospital-56388
06/15/2022, 12:48 PMexecution_mode = "venv"
to the pex_binary
definition when running the pex_binary directly through ./pants run
. However, this seems not to help when first packaging the binary and then executing that as ./app.pex
.happy-kitchen-89482
06/15/2022, 4:31 PMabundant-hospital-56388
06/17/2022, 8:24 AMhappy-kitchen-89482
06/18/2022, 6:23 PMabundant-hospital-56388
06/19/2022, 1:44 PM