Skip to content

Commit 1fe9165

Browse files
committed
Run passing tests with the GIL disabled
In `--disable-gil` builds, `make test` and `make buildbottest` now run all tests not know to fail with `-Xgil=0`. The test runner itself occasionally crashes with the GIL off, so until that's resolved, it takes a `--disable-gil` option to pass `-Xgil=0` to the worker processes.
1 parent 89b1150 commit 1fe9165

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
test.test_asyncio.test_base_events.*
2+
test.test_asyncio.test_ssl.*
3+
test.test_capi.*
4+
test.test_code.*
5+
test.test_compileall.*
6+
test.test_concurrent_futures.*
7+
test.test_enum.*
8+
test.test_fork1.*
9+
test.test_functools.*
10+
test.test_httpservers.*
11+
test.test_imaplib.*
12+
test.test_import.*
13+
test.test_importlib.*
14+
test.test_io.*
15+
test.test_logging.*
16+
test.test_multiprocessing_forkserver.*
17+
test.test_multiprocessing_spawn.*
18+
test.test_pickle.*
19+
test.test_queue.*
20+
test.test_smtpnet.*
21+
test.test_socketserver.*
22+
test.test_ssl.*
23+
test.test_syslog.*
24+
test.test_thread.*
25+
test.test_threadedtempfile.*
26+
test.test_threading.*
27+
test.test_threading_local.*
28+
test.test_threadsignals.*
29+
test.test_urllib2net.*
30+
test.test_weakref.*

Lib/test/libregrtest/cmdline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ def _create_parser():
349349
help='remove old test_python_* directories')
350350
group.add_argument('--bisect', action='store_true',
351351
help='if some tests fail, run test.bisect_cmd on them')
352+
# This option is used to disable the GIL in worker processes until the test
353+
# runner is stable under -Xgil=0.
354+
group.add_argument('--disable-gil', action='store_true',
355+
help='Pass -Xgil=0 to worker processes.')
352356
group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
353357
action='store_false',
354358
help="internal option, don't use it")

Lib/test/libregrtest/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
120120
self.coverage: bool = ns.trace
121121
self.coverage_dir: StrPath | None = ns.coverdir
122122
self.tmp_dir: StrPath | None = ns.tempdir
123+
self.disable_gil: bool = ns.disable_gil
123124

124125
# Randomize
125126
self.randomize: bool = ns.randomize
@@ -480,6 +481,7 @@ def create_run_tests(self, tests: TestTuple):
480481
python_cmd=self.python_cmd,
481482
randomize=self.randomize,
482483
random_seed=self.random_seed,
484+
disable_gil=self.disable_gil,
483485
)
484486

485487
def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:

Lib/test/libregrtest/runtests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class RunTests:
100100
python_cmd: tuple[str, ...] | None
101101
randomize: bool
102102
random_seed: int | str
103+
disable_gil: bool
103104

104105
def copy(self, **override) -> 'RunTests':
105106
state = dataclasses.asdict(self)
@@ -146,6 +147,8 @@ def json_file_use_stdout(self) -> bool:
146147

147148
def create_python_cmd(self) -> list[str]:
148149
python_opts = support.args_from_interpreter_flags()
150+
if self.disable_gil:
151+
python_opts.append("-Xgil=0")
149152
if self.python_cmd is not None:
150153
executable = self.python_cmd
151154
# Remove -E option, since --python=COMMAND can set PYTHON

Makefile.pre.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ MKDIR_P= @MKDIR_P@
7878

7979
MAKESETUP= $(srcdir)/Modules/makesetup
8080

81+
GIL_DISABLED= @GIL_DISABLED@
82+
8183
# Compiler options
8284
OPT= @OPT@
8385
BASECFLAGS= @BASECFLAGS@
@@ -2024,6 +2026,7 @@ TESTOPTS= $(EXTRATESTOPTS)
20242026
TESTPYTHON= $(RUNSHARED) $(PYTHON_FOR_BUILD) $(TESTPYTHONOPTS)
20252027
TESTRUNNER= $(TESTPYTHON) -m test
20262028
TESTTIMEOUT=
2029+
GIL_DISABLED_IGNORELIST= $(srcdir)/Lib/test/gil_disabled_failing_tests.txt
20272030

20282031
# Remove "test_python_*" directories of previous failed test jobs.
20292032
# Pass TESTOPTS options because it can contain --tempdir option.
@@ -2037,6 +2040,10 @@ cleantest: all
20372040
.PHONY: test
20382041
test: all
20392042
$(TESTRUNNER) --fast-ci --timeout=$(TESTTIMEOUT) $(TESTOPTS)
2043+
ifeq ($(GIL_DISABLED),yes)
2044+
$(TESTRUNNER) --fast-ci --timeout=$(TESTTIMEOUT) $(TESTOPTS) \
2045+
--disable-gil --ignorefile=$(GIL_DISABLED_IGNORELIST)
2046+
endif
20402047

20412048
# Run the test suite for both architectures in a Universal build on OSX.
20422049
# Must be run on an Intel box.
@@ -2095,6 +2102,10 @@ buildbottest: all
20952102
pybuildbot.identify "CC='$(CC)'" "CXX='$(CXX)'"; \
20962103
fi
20972104
$(TESTRUNNER) --slow-ci --timeout=$(TESTTIMEOUT) $(TESTOPTS)
2105+
ifeq ($(GIL_DISABLED),yes)
2106+
$(TESTRUNNER) --slow-ci --timeout=$(TESTTIMEOUT) $(TESTOPTS) \
2107+
--disable-gil --ignorefile=$(GIL_DISABLED_IGNORELIST)
2108+
endif
20982109

20992110
.PHONY: pythoninfo
21002111
pythoninfo: all

configure

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,11 +1666,15 @@ AC_ARG_ENABLE([gil],
16661666
)
16671667
AC_MSG_RESULT([$disable_gil])
16681668

1669+
AC_SUBST([GIL_DISABLED])
1670+
GIL_DISABLED=""
1671+
16691672
if test "$disable_gil" = "yes"
16701673
then
16711674
AC_DEFINE([Py_GIL_DISABLED], [1],
16721675
[Define if you want to disable the GIL])
16731676
# Add "t" for "threaded"
1677+
GIL_DISABLED="yes"
16741678
ABIFLAGS="${ABIFLAGS}t"
16751679
fi
16761680

0 commit comments

Comments
 (0)