Skip to content
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

bpo-40453: Add PyConfig._isolated_subinterpreter #19820

Merged
merged 3 commits into from May 1, 2020
Merged

bpo-40453: Add PyConfig._isolated_subinterpreter #19820

merged 3 commits into from May 1, 2020

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 30, 2020

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
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
Copy link
Member Author

vstinner commented May 1, 2020

@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.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

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.

@@ -824,7 +825,7 @@ def f():
t.join()
""")
with file:
interpreters.run_string(self.id, script)
interpreters.run_string(subinterp, script)
Copy link
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.

@@ -65,6 +65,8 @@ PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn);
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);

PyAPI_FUNC(PyThreadState *) _Py_NewInterpreter(int isolated_subinterpreter);
Copy link
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.

None yet

4 participants