Skip to content

Commit c5fa364

Browse files
authored
bpo-40514: Add --with-experimental-isolated-subinterpreters (pythonGH-19926)
Add --with-experimental-isolated-subinterpreters build option to configure: better isolate subinterpreters, experimental build mode. When used, force the usage of the libc malloc() memory allocator, since pymalloc relies on the unique global interpreter lock (GIL).
1 parent 0b1e330 commit c5fa364

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add ``--with-experimental-isolated-subinterpreters`` build option to
2+
``configure``: better isolate subinterpreters, experimental build mode.

Python/preconfig.c

+10
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,17 @@ _PyPreConfig_InitCompatConfig(PyPreConfig *config)
291291
config->coerce_c_locale_warn = 0;
292292

293293
config->dev_mode = -1;
294+
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
295+
/* bpo-40512: pymalloc is not compatible with subinterpreters,
296+
force usage of libc malloc() which is thread-safe. */
297+
#ifdef Py_DEBUG
298+
config->allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG;
299+
#else
300+
config->allocator = PYMEM_ALLOCATOR_MALLOC;
301+
#endif
302+
#else
294303
config->allocator = PYMEM_ALLOCATOR_NOT_SET;
304+
#endif
295305
#ifdef MS_WINDOWS
296306
config->legacy_windows_fs_encoding = -1;
297307
#endif

configure

+28
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ with_computed_gotos
845845
with_ensurepip
846846
with_openssl
847847
with_ssl_default_suites
848+
with_experimental_isolated_subinterpreters
848849
'
849850
ac_precious_vars='build_alias
850851
host_alias
@@ -1575,6 +1576,9 @@ Optional Packages:
15751576
leave OpenSSL's defaults untouched, STRING: use a
15761577
custom string, PROTOCOL_SSLv2 ignores the setting,
15771578
see Doc/library/ssl.rst
1579+
--with-experimental-isolated-subinterpreters
1580+
better isolate subinterpreters, experimental build
1581+
mode (default is no)
15781582
15791583
Some influential environment variables:
15801584
MACHDEP name for machine-dependent library files
@@ -17489,6 +17493,30 @@ $as_echo "#define PY_SSL_DEFAULT_CIPHERS 1" >>confdefs.h
1748917493
fi
1749017494

1749117495

17496+
# --with-experimental-isolated-subinterpreters
17497+
17498+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-experimental-isolated-subinterpreters" >&5
17499+
$as_echo_n "checking for --with-experimental-isolated-subinterpreters... " >&6; }
17500+
17501+
# Check whether --with-experimental-isolated-subinterpreters was given.
17502+
if test "${with_experimental_isolated_subinterpreters+set}" = set; then :
17503+
withval=$with_experimental_isolated_subinterpreters;
17504+
if test "$withval" != no
17505+
then
17506+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
17507+
$as_echo "yes" >&6; };
17508+
$as_echo "#define EXPERIMENTAL_ISOLATED_SUBINTERPRETERS 1" >>confdefs.h
17509+
17510+
else
17511+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17512+
$as_echo "no" >&6; };
17513+
fi
17514+
else
17515+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
17516+
$as_echo "no" >&6; }
17517+
fi
17518+
17519+
1749217520

1749317521
# generate output files
1749417522
ac_config_files="$ac_config_files Makefile.pre Misc/python.pc Misc/python-embed.pc Misc/python-config.sh"

configure.ac

+17
Original file line numberDiff line numberDiff line change
@@ -5717,6 +5717,23 @@ AC_MSG_RESULT(python)
57175717
AC_DEFINE(PY_SSL_DEFAULT_CIPHERS, 1)
57185718
])
57195719

5720+
# --with-experimental-isolated-subinterpreters
5721+
AH_TEMPLATE(EXPERIMENTAL_ISOLATED_SUBINTERPRETERS,
5722+
[Better isolate subinterpreters, experimental build mode.])
5723+
AC_MSG_CHECKING(for --with-experimental-isolated-subinterpreters)
5724+
AC_ARG_WITH(experimental-isolated-subinterpreters,
5725+
AS_HELP_STRING([--with-experimental-isolated-subinterpreters],
5726+
[better isolate subinterpreters, experimental build mode (default is no)]),
5727+
[
5728+
if test "$withval" != no
5729+
then
5730+
AC_MSG_RESULT(yes);
5731+
AC_DEFINE(EXPERIMENTAL_ISOLATED_SUBINTERPRETERS)
5732+
else
5733+
AC_MSG_RESULT(no);
5734+
fi],
5735+
[AC_MSG_RESULT(no)])
5736+
57205737

57215738
# generate output files
57225739
AC_CONFIG_FILES(Makefile.pre Misc/python.pc Misc/python-embed.pc Misc/python-config.sh)

pyconfig.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
/* Define if --enable-ipv6 is specified */
3939
#undef ENABLE_IPV6
4040

41+
/* Better isolate subinterpreters, experimental build mode. */
42+
#undef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
43+
4144
/* Define to 1 if your system stores words within floats with the most
4245
significant word first */
4346
#undef FLOAT_WORDS_BIGENDIAN

0 commit comments

Comments
 (0)