Skip to content

Commit 2ab28b0

Browse files
committed
Test _PyEval_AddPendingCall() instead of Py_AddPendingCall()
Apparently, Py_AddPendingCall() schedules for the main interpreter.
1 parent c8cac69 commit 2ab28b0

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ def subthread():
16451645
@threading_helper.requires_working_threading()
16461646
def test_pending_call_creates_thread(self):
16471647
source = """
1648-
import _testcapi
1648+
import _testinternalcapi
16491649
import threading
16501650
import time
16511651
@@ -1662,7 +1662,7 @@ def callback():
16621662
16631663
def create_pending_call():
16641664
time.sleep(1)
1665-
_testcapi.simple_pending_call(callback)
1665+
_testinternalcapi.simple_pending_call(callback)
16661666
16671667
16681668
threading.Thread(target=create_pending_call).start()

Modules/_testcapimodule.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,16 +2572,6 @@ toggle_reftrace_printer(PyObject *ob, PyObject *arg)
25722572
Py_RETURN_NONE;
25732573
}
25742574

2575-
static PyObject *
2576-
simple_pending_call(PyObject *self, PyObject *callable)
2577-
{
2578-
if (Py_AddPendingCall(_pending_callback, Py_NewRef(callable)) < 0) {
2579-
return NULL;
2580-
}
2581-
2582-
Py_RETURN_NONE;
2583-
}
2584-
25852575
static PyMethodDef TestMethods[] = {
25862576
{"set_errno", set_errno, METH_VARARGS},
25872577
{"test_config", test_config, METH_NOARGS},
@@ -2676,7 +2666,6 @@ static PyMethodDef TestMethods[] = {
26762666
{"test_atexit", test_atexit, METH_NOARGS},
26772667
{"code_offset_to_line", _PyCFunction_CAST(code_offset_to_line), METH_FASTCALL},
26782668
{"toggle_reftrace_printer", toggle_reftrace_printer, METH_O},
2679-
{"simple_pending_call", simple_pending_call, METH_O},
26802669
{NULL, NULL} /* sentinel */
26812670
};
26822671

Modules/_testinternalcapi.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,16 @@ emscripten_set_up_async_input_device(PyObject *self, PyObject *Py_UNUSED(ignored
23762376
}
23772377
#endif
23782378

2379+
static PyObject *
2380+
simple_pending_call(PyObject *self, PyObject *callable)
2381+
{
2382+
if (_PyEval_AddPendingCall(_PyInterpreterState_GET(), _pending_callback, Py_NewRef(callable), 0) < 0) {
2383+
return NULL;
2384+
}
2385+
2386+
Py_RETURN_NONE;
2387+
}
2388+
23792389
static PyMethodDef module_functions[] = {
23802390
{"get_configs", get_configs, METH_NOARGS},
23812391
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -2481,6 +2491,7 @@ static PyMethodDef module_functions[] = {
24812491
#ifdef __EMSCRIPTEN__
24822492
{"emscripten_set_up_async_input_device", emscripten_set_up_async_input_device, METH_NOARGS},
24832493
#endif
2494+
{"simple_pending_call", simple_pending_call, METH_O},
24842495
{NULL, NULL} /* sentinel */
24852496
};
24862497

0 commit comments

Comments
 (0)