Skip to content

Commit

Permalink
Run passing tests with the GIL disabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
swtaarrs committed Mar 7, 2024
1 parent 89b1150 commit 1fe9165
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Lib/test/gil_disabled_failing_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
test.test_asyncio.test_base_events.*
test.test_asyncio.test_ssl.*
test.test_capi.*
test.test_code.*
test.test_compileall.*
test.test_concurrent_futures.*
test.test_enum.*
test.test_fork1.*
test.test_functools.*
test.test_httpservers.*
test.test_imaplib.*
test.test_import.*
test.test_importlib.*
test.test_io.*
test.test_logging.*
test.test_multiprocessing_forkserver.*
test.test_multiprocessing_spawn.*
test.test_pickle.*
test.test_queue.*
test.test_smtpnet.*
test.test_socketserver.*
test.test_ssl.*
test.test_syslog.*
test.test_thread.*
test.test_threadedtempfile.*
test.test_threading.*
test.test_threading_local.*
test.test_threadsignals.*
test.test_urllib2net.*
test.test_weakref.*
4 changes: 4 additions & 0 deletions Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ def _create_parser():
help='remove old test_python_* directories')
group.add_argument('--bisect', action='store_true',
help='if some tests fail, run test.bisect_cmd on them')
# This option is used to disable the GIL in worker processes until the test
# runner is stable under -Xgil=0.
group.add_argument('--disable-gil', action='store_true',
help='Pass -Xgil=0 to worker processes.')
group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
action='store_false',
help="internal option, don't use it")
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self, ns: Namespace, _add_python_opts: bool = False):
self.coverage: bool = ns.trace
self.coverage_dir: StrPath | None = ns.coverdir
self.tmp_dir: StrPath | None = ns.tempdir
self.disable_gil: bool = ns.disable_gil

# Randomize
self.randomize: bool = ns.randomize
Expand Down Expand Up @@ -480,6 +481,7 @@ def create_run_tests(self, tests: TestTuple):
python_cmd=self.python_cmd,
randomize=self.randomize,
random_seed=self.random_seed,
disable_gil=self.disable_gil,
)

def _run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/libregrtest/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class RunTests:
python_cmd: tuple[str, ...] | None
randomize: bool
random_seed: int | str
disable_gil: bool

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

def create_python_cmd(self) -> list[str]:
python_opts = support.args_from_interpreter_flags()
if self.disable_gil:
python_opts.append("-Xgil=0")
if self.python_cmd is not None:
executable = self.python_cmd
# Remove -E option, since --python=COMMAND can set PYTHON
Expand Down
11 changes: 11 additions & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ MKDIR_P= @MKDIR_P@

MAKESETUP= $(srcdir)/Modules/makesetup

GIL_DISABLED= @GIL_DISABLED@

# Compiler options
OPT= @OPT@
BASECFLAGS= @BASECFLAGS@
Expand Down Expand Up @@ -2024,6 +2026,7 @@ TESTOPTS= $(EXTRATESTOPTS)
TESTPYTHON= $(RUNSHARED) $(PYTHON_FOR_BUILD) $(TESTPYTHONOPTS)
TESTRUNNER= $(TESTPYTHON) -m test
TESTTIMEOUT=
GIL_DISABLED_IGNORELIST= $(srcdir)/Lib/test/gil_disabled_failing_tests.txt

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

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

.PHONY: pythoninfo
pythoninfo: all
Expand Down
5 changes: 5 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1666,11 +1666,15 @@ AC_ARG_ENABLE([gil],
)
AC_MSG_RESULT([$disable_gil])

AC_SUBST([GIL_DISABLED])
GIL_DISABLED=""

if test "$disable_gil" = "yes"
then
AC_DEFINE([Py_GIL_DISABLED], [1],
[Define if you want to disable the GIL])
# Add "t" for "threaded"
GIL_DISABLED="yes"
ABIFLAGS="${ABIFLAGS}t"
fi

Expand Down

0 comments on commit 1fe9165

Please sign in to comment.