Merge ~cjwatson/launchpad:py3-readline-libedit-workaround into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 731e8cc9934a16eb88858770ca2498637689169c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-readline-libedit-workaround
Merge into: launchpad:master
Diff against target: 54 lines (+18/-0)
2 files modified
lib/lp/scripts/utilities/test.py (+17/-0)
setup.py (+1/-0)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+392028@code.launchpad.net

Commit message

Work around readline crash in Python 3 on 18.04

Description of the change

On 18.04, importing GTK (which we do in lp.testing.html5browser) indirectly loads libedit, and versions of Python 3 before 3.8.1 crash when importing readline in a process that has libedit loaded (https://bugs.python.org/issue38634, https://bugs.launchpad.net/bugs/1899076). As a result the test suite crashes quite early on.

There's unfortunately no reasonable way to avoid this, because we aren't loading libedit directly and nor are we importing readline directly; they're both quite deeply-buried side-effects of other things. We have to take an unreasonable way instead: stub out the readline module in the test suite on affected systems. This is deliberately kept as narrow as possible, and we should drop it if and when the Python bug is fixed in Ubuntu 18.04 or we no longer care about trying to get Launchpad to run on Python 3 on 18.04.

To post a comment you must log in.
731e8cc... by Colin Watson

Switch conditional order

six.PY3 does rather less work than distro.linux_distribution(), so
evaluate the cheaper one first.

Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/scripts/utilities/test.py b/lib/lp/scripts/utilities/test.py
2index e1e67b8..644c496 100755
3--- a/lib/lp/scripts/utilities/test.py
4+++ b/lib/lp/scripts/utilities/test.py
5@@ -25,6 +25,7 @@ import sys
6 import time
7 import warnings
8
9+import distro
10 import six
11 from zope.testrunner import options
12 from zope.testrunner.feature import Feature
13@@ -34,6 +35,7 @@ from lp.scripts.utilities import (
14 importpedant,
15 warninghandler,
16 )
17+from lp.services.compat import mock
18 from lp.services.config import config
19
20
21@@ -91,6 +93,21 @@ def configure_environment():
22 # Suppress accessibility warning because the test runner does not have UI.
23 os.environ['GTK_MODULES'] = ''
24
25+ if six.PY3 and distro.linux_distribution()[:2] == ('Ubuntu', '18.04'):
26+ # XXX cjwatson 2020-10-09: Certain versions of Python crash when
27+ # importing readline into a process that has libedit loaded
28+ # (https://bugs.python.org/issue38634,
29+ # https://bugs.launchpad.net/bugs/1899076), so stub out readline to
30+ # prevent this. This unfortunately makes debugging less pleasant.
31+ #
32+ # So far the only LTS version of Ubuntu that exhibits this behaviour
33+ # is 18.04; 16.04 doesn't seem to end up loading libedit because its
34+ # libGL is laid out differently in a way that doesn't end up loading
35+ # libedit, and 20.04 has the Python bug fixed. We should drop this
36+ # once 18.04 is fixed or once we no longer care about it, since this
37+ # workaround is pretty nasty.
38+ sys.modules['readline'] = mock.Mock()
39+
40
41 def filter_warnings():
42 # Silence spurious warnings. Note that this does not propagate to
43diff --git a/setup.py b/setup.py
44index e88b299..4e76a25 100644
45--- a/setup.py
46+++ b/setup.py
47@@ -163,6 +163,7 @@ setup(
48 'cssselect',
49 'cssutils',
50 'defusedxml',
51+ 'distro',
52 'dkimpy[ed25519]',
53 'dulwich',
54 'feedparser',

Subscribers

People subscribed via source and target branches

to status/vote changes: