Skip to content

Example no-site flag for subinterpreters module #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: per-interpreter-gil-new
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Include/cpython/initconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ typedef struct {
int allow_daemon_threads;
int check_multi_interp_extensions;
int own_gil;
int site_import;
} _PyInterpreterConfig;

#define _PyInterpreterConfig_INIT \
#define _PyInterpreterConfig_INIT(site) \
{ \
.use_main_obmalloc = 0, \
.allow_fork = 0, \
Expand All @@ -264,6 +265,7 @@ typedef struct {
.allow_daemon_threads = 0, \
.check_multi_interp_extensions = 1, \
.own_gil = 1, \
.site_import = site, \
}

#define _PyInterpreterConfig_LEGACY_INIT \
Expand All @@ -275,6 +277,7 @@ typedef struct {
.allow_daemon_threads = 1, \
.check_multi_interp_extensions = 0, \
.own_gil = 0, \
.site_import = 1, \
}

/* --- Helper functions --------------------------------------- */
Expand Down
17 changes: 10 additions & 7 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,22 @@ _run_script_in_interpreter(PyObject *mod, PyInterpreterState *interp,
static PyObject *
interp_create(PyObject *self, PyObject *args, PyObject *kwds)
{

static char *kwlist[] = {"isolated", NULL};
int isolated = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$i:create", kwlist,
&isolated)) {
static char *kwlist[] = {"isolated", "site", NULL};
int isolated = 1, site=1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$ii:create", kwlist,
&isolated, &site)) {
return NULL;
}
if (!isolated && !site){
// no site requires isolated
PyErr_SetString(PyExc_ValueError, "isolated must be True when combined with site=False");
return NULL;
}

// Create and initialize the new interpreter.
PyThreadState *save_tstate = _PyThreadState_GET();
assert(save_tstate != NULL);
const _PyInterpreterConfig config = isolated
? (_PyInterpreterConfig)_PyInterpreterConfig_INIT
? (_PyInterpreterConfig)_PyInterpreterConfig_INIT(site)
: (_PyInterpreterConfig)_PyInterpreterConfig_LEGACY_INIT;
// XXX Possible GILState issues?
PyThreadState *tstate = NULL;
Expand Down
4 changes: 4 additions & 0 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ init_interp_settings(PyInterpreterState *interp, const _PyInterpreterConfig *con
interp->feature_flags |= Py_RTFLAGS_MULTI_INTERP_EXTENSIONS;
}

if (!config->site_import) {
interp->config.site_import = 0;
}

return _PyStatus_OK();
}

Expand Down