8000 gh-105716: Support Background Threads in Subinterpreters Consistently by ericsnowcurrently · Pull Request #109921 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105716: Support Background Threads in Subinterpreters Consistently #109921

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

Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4e88c2b
Always wait for threads in subinterpreters.
ericsnowcurrently Sep 25, 2023
d08ac68
Add PyInterpreterState_*RunningMain().
ericsnowcurrently Sep 26, 2023
3b07482
Drop interpreter_exists().
ericsnowcurrently Sep 26, 2023
70c4753
Drop PyThreadState_IsRunning().
ericsnowcurrently Sep 26, 2023
678cb3b
Add a TODO.
ericsnowcurrently Sep 26, 2023
5be5a07
For now use the earliest thread state.
ericsnowcurrently Sep 26, 2023
81a1e0b
Add tests.
ericsnowcurrently Sep 26, 2023
c3f497b
Mark the main interpreter as running __main__.
ericsnowcurrently Sep 26, 2023
effa5b4
Call PyInterpreterState_SetNotRunningMain() in the right place.
ericsnowcurrently Sep 26, 2023
41c54b0
Check PyInterpreterState_IsRunningMain() preemptively, for now.
ericsnowcurrently Sep 26, 2023
5fbd940
Add docs.
ericsnowcurrently Sep 26, 2023
8b54c2e
Add a NEWS entry.
ericsnowcurrently Sep 26, 2023
5d1df61
Fix a typo.
ericsnowcurrently Sep 27, 2023
1034a67
Update the docs.
ericsnowcurrently Sep 27, 2023
d57729e
Update the docs.
ericsnowcurrently Sep 27, 2023
4219e2c
Update the docs.
ericsnowcurrently Sep 27, 2023
bfdace2
Drop a dead line.
ericsnowcurrently Sep 27, 2023
ef8af92
Drop an unused parameter.
ericsnowcurrently Sep 27, 2023
566cd08
Drop an 8000 unnecessary variable.
ericsnowcurrently Sep 27, 2023
d14b87a
Update TODO comments.
ericsnowcurrently Sep 27, 2023
1f2a321
Merge branch 'main' into subinterpreters-allow-background-threads
ericsnowcurrently Sep 27, 2023
55d7090
Merge branch 'main' into subinterpreters-allow-background-threads
ericsnowcurrently Sep 29, 2023
399859f
Do not expose the "Running" C-API (for now).
ericsnowcurrently Oct 2, 2023
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
Prev Previous commit
Next Next commit
Add docs.
  • Loading branch information
ericsnowcurrently committed Sep 26, 2023
commit 5fbd940737510ea9b2e2e61cd7b7ad6bcf67c481
36 changes: 36 additions & 0 deletions Doc/c-api/init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,42 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
.. versionadded:: 3.7


.. c:function:: int PyInterpreterState_SetRunningMain(PyInterpreterState *interp)

Indicate that current thread will be executing Python code against
the ``__main__`` module of the given interpreter. This is meant for
use in embedded applications or code that manages subinterpreters.
Calling this is appropriate right before running a script,
e.g. using :c:func:`PyRun_SimpleString`.

If the interpreter is already running then this will raise
:exc:`RuntimeError`.

This must be called in the thread where that will happen.
The caller must hold the GIL. Every call must have a corresponding
call to :c:func:`PyInterpreterState_UnsetRunningMain`.

.. versionadded:: 3.13


.. c:function:: void PyInterpreterState_UnsetRunningMain(PyInterpreterState *interp)

Indicate that the current thread is done running code in the
interpreter's ``__main__`` module. This is the companion to
:c:func:`PyInterpreterState_SetRunningMain`.

.. versionadded:: 3.13


.. c:function:: int PyInterpreterState_IsRunningMain(PyInterpreterState *interp)

Return true (nonzero) if the interpreter is currently running a script
in its ``__main__`` module, false (zero) if not.
See :c:func:`PyInterpreterState_SetRunningMain`.

.. versionadded:: 3.13


.. c:function:: PyObject* PyInterpreterState_GetDict(PyInterpreterState *interp)

Return a dictionary in which interpreter-specific data may be stored.
Expand Down
0