Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 292076a

Browse filesBrowse files
gh-104109: Expose Py_NewInterpreterFromConfig() in the Public C-API (gh-104110)
We also expose PyInterpreterConfig. This is part of the PEP 684 (per-interpreter GIL) implementation. We will add docs as soon as we can. FYI, I'm adding the new config field for per-interpreter GIL in gh-99114.
1 parent de64e75 commit 292076a
Copy full SHA for 292076a

File tree

Expand file treeCollapse file tree

6 files changed

+22
-16
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+22
-16
lines changed

‎Include/cpython/initconfig.h

Copy file name to clipboardExpand all lines: Include/cpython/initconfig.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ typedef struct {
252252
int allow_threads;
253253
int allow_daemon_threads;
254254
int check_multi_interp_extensions;
255-
} _PyInterpreterConfig;
255+
} PyInterpreterConfig;
256256

257257
#define _PyInterpreterConfig_INIT \
258258
{ \

‎Include/cpython/pylifecycle.h

Copy file name to clipboardExpand all lines: Include/cpython/pylifecycle.h
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn);
6262
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
6363
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
6464

65-
PyAPI_FUNC(PyStatus) _Py_NewInterpreterFromConfig(
65+
PyAPI_FUNC(PyStatus) Py_NewInterpreterFromConfig(
6666
PyThreadState **tstate_p,
67-
const _PyInterpreterConfig *config);
67+
const PyInterpreterConfig *config);
6868

6969
typedef void (*atexit_datacallbackfunc)(void *);
7070
PyAPI_FUNC(int) _Py_AtExit(
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
We've added ``Py_NewInterpreterFromConfig()`` and ``PyInterpreterConfig`` to
2+
the public C-API (but not the stable ABI; not yet at least). The new
3+
function may be used to create a new interpreter with various features
4+
configured. The function was added to support PEP 684 (per-interpreter
5+
GIL).

‎Modules/_testcapimodule.c

Copy file name to clipboardExpand all lines: Modules/_testcapimodule.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,15 +1538,15 @@ run_in_subinterp_with_config(PyObject *self, PyObject *args, PyObject *kwargs)
15381538

15391539
PyThreadState_Swap(NULL);
15401540

1541-
const _PyInterpreterConfig config = {
1541+
const PyInterpreterConfig config = {
15421542
.use_main_obmalloc = use_main_obmalloc,
15431543
.allow_fork = allow_fork,
15441544
.allow_exec = allow_exec,
15451545
.allow_threads = allow_threads,
15461546
.allow_daemon_threads = allow_daemon_threads,
15471547
.check_multi_interp_extensions = check_multi_interp_extensions,
15481548
};
1549-
PyStatus status = _Py_NewInterpreterFromConfig(&substate, &config);
1549+
PyStatus status = Py_NewInterpreterFromConfig(&substate, &config);
15501550
if (PyStatus_Exception(status)) {
15511551
/* Since no new thread state was created, there is no exception to
15521552
propagate; raise a fresh one after swapping in the old thread

‎Modules/_xxsubinterpretersmodule.c

Copy file name to clipboardExpand all lines: Modules/_xxsubinterpretersmodule.c
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,12 @@ interp_create(PyObject *self, PyObject *args, PyObject *kwds)
513513

514514
// Create and initialize the new interpreter.
515515
PyThreadState *save_tstate = _PyThreadState_GET();
516-
const _PyInterpreterConfig config = isolated
517-
? (_PyInterpreterConfig)_PyInterpreterConfig_INIT
518-
: (_PyInterpreterConfig)_PyInterpreterConfig_LEGACY_INIT;
516+
const PyInterpreterConfig config = isolated
517+
? (PyInterpreterConfig)_PyInterpreterConfig_INIT
518+
: (PyInterpreterConfig)_PyInterpreterConfig_LEGACY_INIT;
519519
// XXX Possible GILState issues?
520520
PyThreadState *tstate = NULL;
521-
PyStatus status = _Py_NewInterpreterFromConfig(&tstate, &config);
521+
PyStatus status = Py_NewInterpreterFromConfig(&tstate, &config);
522522
PyThreadState_Swap(save_tstate);
523523
if (PyStatus_Exception(status)) {
524524
/* Since no new thread state was created, there is no exception to

‎Python/pylifecycle.c

Copy file name to clipboardExpand all lines: Python/pylifecycle.c
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ pycore_init_runtime(_PyRuntimeState *runtime,
546546

547547

548548
static PyStatus
549-
init_interp_settings(PyInterpreterState *interp, const _PyInterpreterConfig *config)
549+
init_interp_settings(PyInterpreterState *interp,
550+
const PyInterpreterConfig *config)
550551
{
551552
assert(interp->feature_flags == 0);
552553

@@ -631,7 +632,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
631632
return status;
632633
}
633634

634-
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
635+
const PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
635636
status = init_interp_settings(interp, &config);
636637
if (_PyStatus_EXCEPTION(status)) {
637638
return status;
@@ -1991,7 +1992,7 @@ Py_Finalize(void)
19911992
*/
19921993

19931994
static PyStatus
1994-
new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
1995+
new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
19951996
{
19961997
PyStatus status;
19971998

@@ -2079,8 +2080,8 @@ new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
20792080
}
20802081

20812082
PyStatus
2082-
_Py_NewInterpreterFromConfig(PyThreadState **tstate_p,
2083-
const _PyInterpreterConfig *config)
2083+
Py_NewInterpreterFromConfig(PyThreadState **tstate_p,
2084+
const PyInterpreterConfig *config)
20842085
{
20852086
return new_interpreter(tstate_p, config);
20862087
}
@@ -2089,8 +2090,8 @@ PyThreadState *
20892090
Py_NewInterpreter(void)
20902091
{
20912092
PyThreadState *tstate = NULL;
2092-
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
2093-
PyStatus status = _Py_NewInterpreterFromConfig(&tstate, &config);
2093+
const PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
2094+
PyStatus status = new_interpreter(&tstate, &config);
20942095
if (_PyStatus_EXCEPTION(status)) {
20952096
Py_ExitStatusException(status);
20962097
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.