Skip to content

bpo-40453: Add PyConfig._isolated_subinterpreter#19820

Merged
vstinner merged 3 commits into
python:masterfrom
vstinner:isolated_subinterpreters
May 1, 2020
Merged

bpo-40453: Add PyConfig._isolated_subinterpreter#19820
vstinner merged 3 commits into
python:masterfrom
vstinner:isolated_subinterpreters

Conversation

@vstinner

@vstinner vstinner commented Apr 30, 2020

Copy link
Copy Markdown
Member

An isolated subinterpreter cannot spawn threads, spawn a child
process or call os.fork().

  • Add private _Py_NewInterpreter(isolated_subinterpreter) function.
  • Add isolated=True keyword-only parameter to
    _xxsubinterpreters.create().
  • Allow again os.fork() in "non-isolated" subinterpreters.

https://bugs.python.org/issue40453

An isolated subinterpreter cannot spawn threads, spawn a child
process or call os.fork().

* Add private _Py_NewInterpreter(isolated_subinterpreter) function.
* Add isolated=True keyword-only parameter to
  _xxsubinterpreters.create().
* Allow again os.fork() in "non-isolated" subinterpreters.
@vstinner

Copy link
Copy Markdown
Member Author

This change is related to https://www.python.org/dev/peps/pep-0554/

PyConfig._isolated_subinterpreter can be used by import to reject C extensions which don't implement multiphase initialization (PEP 489).

@vstinner

vstinner commented May 1, 2020

Copy link
Copy Markdown
Member Author

@ericsnowcurrently: I chose to aggressively disallow threads and subprocesses. The idea is to only allow them later once we will have more time properly test them once we will have a per-interpreter GIL.

@ericsnowcurrently ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (maybe could use a few more tests, as noted)

Presumably we will do the PEP 489 check in a separate PR.

""")
with file:
interpreters.run_string(self.id, script)
interpreters.run_string(subinterp, script)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth having a test that assertRaises() when isolated is True. Likewise for the other restrictions.

PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);

PyAPI_FUNC(PyThreadState *) _Py_NewInterpreter(int isolated_subinterpreter);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we talked about, this is a good place to start. :)

@vstinner
vstinner merged commit 252346a into python:master May 1, 2020
@vstinner
vstinner deleted the isolated_subinterpreters branch May 1, 2020 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants