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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 44 commits into
base: main
Choose a base branch
Loading
from
Draft
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1828b9a
Implement interpreter state reference counting.
ZeroIntensity Apr 24, 2025
d0895f9
Add a test for interpreter reference counts.
ZeroIntensity Apr 24, 2025
5c3ee8d
Add thread state daemon-ness that doesn't work yet.
ZeroIntensity Apr 25, 2025
7b9ac59
Add untested implementation of non-daemon native threads.
ZeroIntensity Apr 25, 2025
0868c15
Add a test for PyThreadState_SetDaemon().
ZeroIntensity Apr 25, 2025
e9ea644
Add untested implementation of Ensure()/Release() that probably doesn…
ZeroIntensity Apr 25, 2025
0ebdca4
Change some comments.
ZeroIntensity Apr 25, 2025
40989de
Add a test that I'm sure doesn't work.
ZeroIntensity Apr 25, 2025
d501f35
Use the interpreter's reference count and native thread countdown as …
ZeroIntensity Apr 25, 2025
c5ec89c
Fix the countdown decrement.
ZeroIntensity Apr 26, 2025
4e1f599
Remove unused variable.
ZeroIntensity Apr 26, 2025
3127a3f
Test for PyGILState_Ensure()
ZeroIntensity Apr 26, 2025
82b5b9f
Fix the test for the new reference counting.
ZeroIntensity Apr 26, 2025
fda9886
Add PyInterpreterState_Lookup()
ZeroIntensity Apr 26, 2025
f7723c0
Fix a few bugs and add a test.
ZeroIntensity Apr 26, 2025
62e9549
Add a test for PyThreadState_Ensure() across interpreters.
ZeroIntensity Apr 27, 2025
bc60630
Remove an artifact from old approach.
ZeroIntensity Apr 28, 2025
9d8d526
Fix test from earlier semantics.
ZeroIntensity Apr 28, 2025
54b0ce0
Remove 'daemonness' as a property of a thread.
ZeroIntensity May 22, 2025
5955de6
Add strong interpreter reference functions.
ZeroIntensity May 22, 2025
92cf906
Implement weak references.
ZeroIntensity May 22, 2025
b0d0673
Fix some thread safety issues regarding interpreter deletion.
ZeroIntensity May 22, 2025
0a15beb
Merge from main branch.
ZeroIntensity May 22, 2025
16d79de
Implement new version of PyThreadState_Ensure() and PyThreadState_Rel…
ZeroIntensity May 22, 2025
c2bffcd
Use the new APIs in the tests.
ZeroIntensity May 22, 2025
911c6b5
Fix _testcapi.
ZeroIntensity May 22, 2025
b84fa90
Fix the ensure counter.
ZeroIntensity May 22, 2025
9ccf6bd
Add the test to test_embed.
ZeroIntensity May 22, 2025
481caf5
Allow the wait to be interrupted by CTRL+C.
ZeroIntensity May 22, 2025
71e1aec
Print the error before bailing out.
ZeroIntensity May 22, 2025
d661578
Updates for the new proposal.
ZeroIntensity May 28, 2025
4249c5d
Bikeshedding.
ZeroIntensity May 28, 2025
71f2fd7
Apply suggestions from code review
ZeroIntensity May 28, 2025
03ccb38
Fix failing build.
ZeroIntensity May 29, 2025
bca65fb
Rename parameter.
ZeroIntensity May 29, 2025
510ade1
Fix formatting.
ZeroIntensity May 29, 2025
3971408
Add tstate check.
ZeroIntensity May 29, 2025
6c4c52b
Move to pycore_pystate.h
ZeroIntensity May 29, 2025
64920a8
Revert "Move to pycore_pystate.h"
ZeroIntensity May 29, 2025
05436f3
Use an exponential wait time for the event.
ZeroIntensity May 29, 2025
02bc2d7
Mark function as static.
ZeroIntensity May 29, 2025
03fa2af
Update fatal error message.
ZeroIntensity May 29, 2025
b955d85
Remove incorrect assertion.
ZeroIntensity May 29, 2025
5236700
Add a comment regarding PyMem_RawMalloc()
ZeroIntensity May 29, 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
Prev Previous commit
Next Next commit
Add a test that I'm sure doesn't work.
  • Loading branch information
ZeroIntensity committed Apr 25, 2025
commit 40989de0553cda4882acc9efa4cd603767b48233
57 changes: 47 additions & 10 deletions 57 Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,15 @@ test_get_incomplete_frame(void)
return result;
}

const char *THREAD_CODE = "import time\n"
ZeroIntensity marked this conversation as resolved.
Show resolved Hide resolved
"time.sleep(0.2)\n"
"def fib(n):\n"
" if n <= 1:\n"
" return n\n"
" else:\n"
" return fib(n - 1) + fib(n - 2)\n"
"fib(10)";

static void
non_daemon_native(void *arg)
{
Expand All @@ -2350,15 +2359,7 @@ non_daemon_native(void *arg)
int res = PyThreadState_SetDaemon(0);
assert(res == 1);
_PyEvent_Notify(event);
const char *code = "import time\n"
"time.sleep(0.2)\n"
"def fib(n):\n"
" if n <= 1:\n"
" return n\n"
" else:\n"
" return fib(n - 1) + fib(n - 2)\n"
"fib(10)";
res = PyRun_SimpleString(code);
res = PyRun_SimpleString(THREAD_CODE);
assert(res == 0);
PyThreadState_Clear(tstate);
PyThreadState_Swap(NULL);
Expand All @@ -2371,7 +2372,7 @@ test_non_daemon_native_thread(void)
_testembed_Py_InitializeFromConfig();
PyThread_handle_t handle;
PyThread_ident_t ident;
PyEvent event;
PyEvent event = {0};
if (PyThread_start_joinable_thread(non_daemon_native, &event,
&ident, &handle) < 0) {
return -1;
Expand All @@ -2381,6 +2382,41 @@ test_non_daemon_native_thread(void)
return 0;
}

typedef struct {
PyInterpreterState *interp;
PyEvent *event;
} ThreadData;

static void
do_tstate_ensure(void *arg)
{
ThreadData *data = (ThreadData *)arg;
PyEvent *event = data->event;
int res = PyThreadState_Ensure(data->interp);
assert(res == 0);
_PyEvent_Notify(event);
res = PyRun_SimpleString(THREAD_CODE);
assert(res == 0);
PyThreadState_Release();
}

static int
test_thread_state_ensure(void)
{
_testembed_Py_InitializeFromConfig();
PyThread_handle_t handle;
PyThread_ident_t ident;
PyEvent event = {0};
ThreadData data = { PyInterpreterState_Hold(), &event };
if (PyThread_start_joinable_thread(non_daemon_native, &data,
&ident, &handle) < 0) {
return -1;
}
PyEvent_Wait(&event);
Py_Finalize();
return 0;
}

/* *********************************************************
* List of test cases and the function that implements it.
*
Expand Down Expand Up @@ -2471,6 +2507,7 @@ static struct TestCase TestCases[] = {
#endif
{"test_get_incomplete_frame", test_get_incomplete_frame},
{"test_non_daemon_native_thread", test_non_daemon_native_thread},
{"test_thread_state_ensure", test_thread_state_ensure},

{NULL, NULL}
};
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.