Skip to content

Commit 9512ad7

Browse files
authored
[3.9] bpo-40514: Remove --with-experimental-isolated-subinterpreters in 3.9 (GH-20228)
Remove --with-experimental-isolated-subinterpreters configure option in Python 3.9: the experiment continues in the master branch, but it's no longer needed in 3.9.
1 parent b008445 commit 9512ad7

21 files changed

+7
-236
lines changed

Include/internal/pycore_ceval.h

-4
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ extern PyObject *_PyEval_EvalCode(
5050
PyObject *kwdefs, PyObject *closure,
5151
PyObject *name, PyObject *qualname);
5252

53-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
54-
extern int _PyEval_ThreadsInitialized(PyInterpreterState *interp);
55-
#else
5653
extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
57-
#endif
5854
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
5955
extern void _PyEval_FiniGIL(PyThreadState *tstate);
6056

Include/internal/pycore_interp.h

-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ struct _ceval_state {
4646
/* Request for dropping the GIL */
4747
_Py_atomic_int gil_drop_request;
4848
struct _pending_calls pending;
49-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
50-
struct _gil_runtime_state gil;
51-
#endif
5249
};
5350

5451
/* fs_codec.encoding is initialized to NULL.

Include/internal/pycore_pystate.h

-12
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,10 @@ _Py_ThreadCanHandlePendingCalls(void)
4949
/* Variable and macro for in-line access to current thread
5050
and interpreter state */
5151

52-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
53-
PyAPI_FUNC(PyThreadState*) _PyThreadState_GetTSS(void);
54-
#endif
55-
5652
static inline PyThreadState*
5753
_PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
5854
{
59-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
60-
return _PyThreadState_GetTSS();
61-
#else
6255
return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->gilstate.tstate_current);
63-
#endif
6456
}
6557

6658
/* Get the current Python thread state.
@@ -75,11 +67,7 @@ _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
7567
static inline PyThreadState*
7668
_PyThreadState_GET(void)
7769
{
78-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
79-
return _PyThreadState_GetTSS();
80-
#else
8170
return _PyRuntimeState_GetThreadState(&_PyRuntime);
82-
#endif
8371
}
8472

8573
/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */

Include/internal/pycore_runtime.h

-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ struct _ceval_runtime_state {
1919
the main thread of the main interpreter can handle signals: see
2020
_Py_ThreadCanHandleSignals(). */
2121
_Py_atomic_int signals_pending;
22-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
2322
struct _gil_runtime_state gil;
24-
#endif
2523
};
2624

2725
/* GIL state */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove ``--with-experimental-isolated-subinterpreters`` configure option in
2+
Python 3.9: the experiment continues in the master branch, but it's no
3+
longer needed in 3.9.

Modules/_xxsubinterpretersmodule.c

-15
Original file line numberDiff line numberDiff line change
@@ -1939,20 +1939,6 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
19391939
return -1;
19401940
}
19411941

1942-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
1943-
// Switch to interpreter.
1944-
PyThreadState *new_tstate = PyInterpreterState_ThreadHead(interp);
1945-
PyThreadState *save1 = PyEval_SaveThread();
1946-
1947-
(void)PyThreadState_Swap(new_tstate);
1948-
1949-
// Run the script.
1950-
_sharedexception *exc = NULL;
1951-
int result = _run_script(interp, codestr, shared, &exc);
1952-
1953-
// Switch back.
1954-
PyEval_RestoreThread(save1);
1955-
#else
19561942
// Switch to interpreter.
19571943
PyThreadState *save_tstate = NULL;
19581944
if (interp != PyInterpreterState_Get()) {
@@ -1970,7 +1956,6 @@ _run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
19701956
if (save_tstate != NULL) {
19711957
PyThreadState_Swap(save_tstate);
19721958
}
1973-
#endif
19741959

19751960
// Propagate any exception out to the caller.
19761961
if (exc != NULL) {

Modules/gcmodule.c

-8
Original file line numberDiff line numberDiff line change
@@ -1181,14 +1181,6 @@ collect(PyThreadState *tstate, int generation,
11811181
_PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
11821182
GCState *gcstate = &tstate->interp->gc;
11831183

1184-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
1185-
if (tstate->interp->config._isolated_interpreter) {
1186-
// bpo-40533: The garbage collector must not be run on parallel on
1187-
// Python objects shared by multiple interpreters.
1188-
return 0;
1189-
}
1190-
#endif
1191-
11921184
if (gcstate->debug & DEBUG_STATS) {
11931185
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
11941186
show_stats_each_generations(gcstate);

Objects/dictobject.c

-6
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,6 @@ static uint64_t pydict_global_version = 0;
251251
#define PyDict_MAXFREELIST 80
252252
#endif
253253

254-
/* bpo-40521: dict free lists are shared by all interpreters. */
255-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
256-
# undef PyDict_MAXFREELIST
257-
# define PyDict_MAXFREELIST 0
258-
#endif
259-
260254
#if PyDict_MAXFREELIST > 0
261255
static PyDictObject *free_list[PyDict_MAXFREELIST];
262256
static int numfree = 0;

Objects/frameobject.c

-6
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,6 @@ static PyGetSetDef frame_getsetlist[] = {
559559
/* max value for numfree */
560560
#define PyFrame_MAXFREELIST 200
561561

562-
/* bpo-40521: frame free lists are shared by all interpreters. */
563-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
564-
# undef PyFrame_MAXFREELIST
565-
# define PyFrame_MAXFREELIST 0
566-
#endif
567-
568562
#if PyFrame_MAXFREELIST > 0
569563
static PyFrameObject *free_list = NULL;
570564
static int numfree = 0; /* number of frames currently in free_list */

Objects/listobject.c

-6
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
101101
# define PyList_MAXFREELIST 80
102102
#endif
103103

104-
/* bpo-40521: list free lists are shared by all interpreters. */
105-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
106-
# undef PyList_MAXFREELIST
107-
# define PyList_MAXFREELIST 0
108-
#endif
109-
110104
static PyListObject *free_list[PyList_MAXFREELIST];
111105
static int numfree = 0;
112106

Objects/tupleobject.c

-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ class tuple "PyTupleObject *" "&PyTuple_Type"
2222
#define PyTuple_MAXFREELIST 2000 /* Maximum number of tuples of each size to save */
2323
#endif
2424

25-
/* bpo-40521: tuple free lists are shared by all interpreters. */
26-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
27-
# undef PyTuple_MAXSAVESIZE
28-
# define PyTuple_MAXSAVESIZE 0
29-
#endif
30-
3125
#if PyTuple_MAXSAVESIZE > 0
3226
/* Entries 1 up to PyTuple_MAXSAVESIZE are free lists, entry 0 is the empty
3327
tuple () of which at most one instance will be allocated.

Objects/typeobject.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ class object "PyObject *" "&PyBaseObject_Type"
1919

2020
#include "clinic/typeobject.c.h"
2121

22-
/* bpo-40521: Type method cache is shared by all subinterpreters */
23-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
24-
# define MCACHE
25-
#endif
22+
#define MCACHE
2623

2724
#ifdef MCACHE
2825
/* Support type attribute cache */
@@ -63,10 +60,7 @@ static size_t method_cache_misses = 0;
6360
static size_t method_cache_collisions = 0;
6461
#endif
6562

66-
/* bpo-40521: Interned strings are shared by all subinterpreters */
67-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
68-
# define INTERN_NAME_STRINGS
69-
#endif
63+
#define INTERN_NAME_STRINGS
7064

7165
/* alphabetical order */
7266
_Py_IDENTIFIER(__abstractmethods__);

Objects/unicodeobject.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ extern "C" {
198198
# define OVERALLOCATE_FACTOR 4
199199
#endif
200200

201-
/* bpo-40521: Interned strings are shared by all interpreters. */
202-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
203-
# define INTERNED_STRINGS
204-
#endif
201+
#define INTERNED_STRINGS
205202

206203
/* This dictionary holds all interned unicode strings. Note that references
207204
to strings in this dictionary are *not* counted in the string's ob_refcnt.
@@ -288,10 +285,7 @@ unicode_decode_utf8(const char *s, Py_ssize_t size,
288285
/* List of static strings. */
289286
static _Py_Identifier *static_strings = NULL;
290287

291-
/* bpo-40521: Latin1 singletons are shared by all interpreters. */
292-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
293-
# define LATIN1_SINGLETONS
294-
#endif
288+
#define LATIN1_SINGLETONS
295289

296290
#ifdef LATIN1_SINGLETONS
297291
/* Single character Unicode strings in the Latin-1 range are being

Python/ceval.c

-55
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,6 @@ ensure_tstate_not_null(const char *func, PyThreadState *tstate)
250250
}
251251

252252

253-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
254-
int
255-
_PyEval_ThreadsInitialized(PyInterpreterState *interp)
256-
{
257-
return gil_created(&interp->ceval.gil);
258-
}
259-
260-
int
261-
PyEval_ThreadsInitialized(void)
262-
{
263-
// Fatal error if there is no current interpreter
264-
PyInterpreterState *interp = PyInterpreterState_Get();
265-
return _PyEval_ThreadsInitialized(interp);
266-
}
267-
#else
268253
int
269254
_PyEval_ThreadsInitialized(_PyRuntimeState *runtime)
270255
{
@@ -277,25 +262,18 @@ PyEval_ThreadsInitialized(void)
277262
_PyRuntimeState *runtime = &_PyRuntime;
278263
return _PyEval_ThreadsInitialized(runtime);
279264
}
280-
#endif
281265

282266
PyStatus
283267
_PyEval_InitGIL(PyThreadState *tstate)
284268
{
285-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
286269
if (!_Py_IsMainInterpreter(tstate)) {
287270
/* Currently, the GIL is shared by all interpreters,
288271
and only the main interpreter is responsible to create
289272
and destroy it. */
290273
return _PyStatus_OK();
291274
}
292-
#endif
293275

294-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
295-
struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
296-
#else
297276
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
298-
#endif
299277
assert(!gil_created(gil));
300278

301279
PyThread_init_thread();
@@ -310,20 +288,14 @@ _PyEval_InitGIL(PyThreadState *tstate)
310288
void
311289
_PyEval_FiniGIL(PyThreadState *tstate)
312290
{
313-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
314291
if (!_Py_IsMainInterpreter(tstate)) {
315292
/* Currently, the GIL is shared by all interpreters,
316293
and only the main interpreter is responsible to create
317294
and destroy it. */
318295
return;
319296
}
320-
#endif
321297

322-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
323-
struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
324-
#else
325298
struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
326-
#endif
327299
if (!gil_created(gil)) {
328300
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
329301
yet: do nothing. */
@@ -408,13 +380,9 @@ PyEval_AcquireThread(PyThreadState *tstate)
408380
take_gil(tstate);
409381

410382
struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
411-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
412-
(void)_PyThreadState_Swap(gilstate, tstate);
413-
#else
414383
if (_PyThreadState_Swap(gilstate, tstate) != NULL) {
415384
Py_FatalError("non-NULL old thread state");
416385
}
417-
#endif
418386
}
419387

420388
void
@@ -444,11 +412,7 @@ _PyEval_ReInitThreads(_PyRuntimeState *runtime)
444412
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
445413
ensure_tstate_not_null(__func__, tstate);
446414

447-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
448-
struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
449-
#else
450415
struct _gil_runtime_state *gil = &runtime->ceval.gil;
451-
#endif
452416
if (!gil_created(gil)) {
453417
return;
454418
}
@@ -480,21 +444,12 @@ PyThreadState *
480444
PyEval_SaveThread(void)
481445
{
482446
_PyRuntimeState *runtime = &_PyRuntime;
483-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
484-
PyThreadState *old_tstate = _PyThreadState_GET();
485-
PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, old_tstate);
486-
#else
487447
PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
488-
#endif
489448
ensure_tstate_not_null(__func__, tstate);
490449

491450
struct _ceval_runtime_state *ceval = &runtime->ceval;
492451
struct _ceval_state *ceval2 = &tstate->interp->ceval;
493-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
494-
assert(gil_created(&ceval2->gil));
495-
#else
496452
assert(gil_created(&ceval->gil));
497-
#endif
498453
drop_gil(ceval, ceval2, tstate);
499454
return tstate;
500455
}
@@ -753,9 +708,7 @@ void
753708
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
754709
{
755710
_Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
756-
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
757711
_gil_initialize(&ceval->gil);
758-
#endif
759712
}
760713

761714
int
@@ -771,10 +724,6 @@ _PyEval_InitState(struct _ceval_state *ceval)
771724
return -1;
772725
}
773726

774-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
775-
_gil_initialize(&ceval->gil);
776-
#endif
777-
778727
return 0;
779728
}
780729

@@ -919,13 +868,9 @@ eval_frame_handle_pending(PyThreadState *tstate)
919868

920869
take_gil(tstate);
921870

922-
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
923-
(void)_PyThreadState_Swap(&runtime->gilstate, tstate);
924-
#else
925871
if (_PyThreadState_Swap(&runtime->gilstate, tstate) != NULL) {
926872
Py_FatalError("orphan tstate");
927873
}
928-
#endif
929874
}
930875

931876
/* Check for asynchronous exception. */

0 commit comments

Comments
 (0)