Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Implement PEP 788#133110

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
ZeroIntensity wants to merge30 commits intopython:main
base:main
Choose a base branch
Loading
fromZeroIntensity:pep-788-impl
Draft
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
30 commits
Select commitHold shift + click to select a range
1828b9a
Implement interpreter state reference counting.
ZeroIntensityApr 24, 2025
d0895f9
Add a test for interpreter reference counts.
ZeroIntensityApr 24, 2025
5c3ee8d
Add thread state daemon-ness that doesn't work yet.
ZeroIntensityApr 25, 2025
7b9ac59
Add untested implementation of non-daemon native threads.
ZeroIntensityApr 25, 2025
0868c15
Add a test for PyThreadState_SetDaemon().
ZeroIntensityApr 25, 2025
e9ea644
Add untested implementation of Ensure()/Release() that probably doesn…
ZeroIntensityApr 25, 2025
0ebdca4
Change some comments.
ZeroIntensityApr 25, 2025
40989de
Add a test that I'm sure doesn't work.
ZeroIntensityApr 25, 2025
d501f35
Use the interpreter's reference count and native thread countdown as …
ZeroIntensityApr 25, 2025
c5ec89c
Fix the countdown decrement.
ZeroIntensityApr 26, 2025
4e1f599
Remove unused variable.
ZeroIntensityApr 26, 2025
3127a3f
Test for PyGILState_Ensure()
ZeroIntensityApr 26, 2025
82b5b9f
Fix the test for the new reference counting.
ZeroIntensityApr 26, 2025
fda9886
Add PyInterpreterState_Lookup()
ZeroIntensityApr 26, 2025
f7723c0
Fix a few bugs and add a test.
ZeroIntensityApr 26, 2025
62e9549
Add a test for PyThreadState_Ensure() across interpreters.
ZeroIntensityApr 27, 2025
bc60630
Remove an artifact from old approach.
ZeroIntensityApr 28, 2025
9d8d526
Fix test from earlier semantics.
ZeroIntensityApr 28, 2025
54b0ce0
Remove 'daemonness' as a property of a thread.
ZeroIntensityMay 22, 2025
5955de6
Add strong interpreter reference functions.
ZeroIntensityMay 22, 2025
92cf906
Implement weak references.
ZeroIntensityMay 22, 2025
b0d0673
Fix some thread safety issues regarding interpreter deletion.
ZeroIntensityMay 22, 2025
0a15beb
Merge from main branch.
ZeroIntensityMay 22, 2025
16d79de
Implement new version of PyThreadState_Ensure() and PyThreadState_Rel…
ZeroIntensityMay 22, 2025
c2bffcd
Use the new APIs in the tests.
ZeroIntensityMay 22, 2025
911c6b5
Fix _testcapi.
ZeroIntensityMay 22, 2025
b84fa90
Fix the ensure counter.
ZeroIntensityMay 22, 2025
9ccf6bd
Add the test to test_embed.
ZeroIntensityMay 22, 2025
481caf5
Allow the wait to be interrupted by CTRL+C.
ZeroIntensityMay 22, 2025
71e1aec
Print the error before bailing out.
ZeroIntensityMay 22, 2025
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
PrevPrevious commit
NextNext commit
Add PyInterpreterState_Lookup()
  • Loading branch information
@ZeroIntensity
ZeroIntensity committedApr 26, 2025
commitfda9886edd26ed7a7e1946f5030cfe96bcbbe2a6
2 changes: 2 additions & 0 deletionsInclude/cpython/pystate.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -283,6 +283,8 @@ PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
* PyThreadState_Ensure() or PyInterpreterState_Release(). */
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Hold(void);

PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Lookup(int64_t interp_id);

/* Release a reference to an interpreter incremented by PyInterpreterState_Hold() */
PyAPI_FUNC(void) PyInterpreterState_Release(PyInterpreterState *interp);

Expand Down
26 changes: 23 additions & 3 deletionsPython/pystate.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3074,9 +3074,6 @@ _PyThreadState_CheckConsistency(PyThreadState *tstate)
int
_PyThreadState_MustExit(PyThreadState *tstate)
{
if (!tstate->daemon) {
return 0;
}
int state = _Py_atomic_load_int_relaxed(&tstate->state);
return state == _Py_THREAD_SHUTTING_DOWN;
}
Expand DownExpand Up@@ -3221,6 +3218,29 @@ PyInterpreterState_Hold(void)
return interp;
}

PyInterpreterState *
PyInterpreterState_Lookup(int64_t interp_id)
{
PyInterpreterState *interp = _PyInterpreterState_LookUpID(interp_id);
if (interp == NULL) {
return NULL;
}
HEAD_LOCK(&_PyRuntime); // Prevent deletion
struct _Py_finalizing_threads finalizing = interp->threads.finalizing;
PyMutex *mutex = &finalizing.mutex;
PyMutex_Lock(mutex); // Synchronize TOCTOU with the event flag
if (_PyEvent_IsSet(&finalizing.finished)) {
/* Interpreter has already finished threads */
interp = NULL;
} else {
_Py_atomic_add_ssize(&finalizing.countdown, 1);
}
PyMutex_Unlock(mutex);
HEAD_UNLOCK(&_PyRuntime);

return interp;
}

void
PyInterpreterState_Release(PyInterpreterState *interp)
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp