Skip to content

Commit 7e7ce09

Browse files
author
Anselm Kruis
committed
Stackless issue python#246: fix assertion errors caused by test_outside
Calling test_outside from a non main tasklet didn't work. (cherry picked from commit 877f2c7)
1 parent 4c7f020 commit 7e7ce09

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Stackless/module/stacklessmodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,9 @@ test_outside(PyObject *self)
969969
{
970970
PyThreadState *ts = PyThreadState_GET();
971971
PyTaskletObject *stmain = ts->st.main;
972+
if (PyTasklet_Scheduled(stmain) && !PyTasklet_IsCurrent(stmain))
973+
RUNTIME_ERROR("main tasklet is still scheduled", NULL);
974+
PyTaskletObject *current;
972975
PyCStackObject *initial_stub = ts->st.initial_stub;
973976
PyFrameObject *f = SLP_CURRENT_FRAME(ts);
974977
int recursion_depth = ts->recursion_depth;
@@ -989,7 +992,7 @@ test_outside(PyObject *self)
989992
ts->st.nesting_level = 0;
990993
SLP_SET_CURRENT_FRAME(ts, NULL);
991994
ts->recursion_depth = 0;
992-
slp_current_remove();
995+
current = slp_current_remove();
993996
while (ts->st.runcount > 0) {
994997
Py_DECREF(ret);
995998
ret = PyStackless_Schedule(Py_None, 0);
@@ -1004,7 +1007,7 @@ test_outside(PyObject *self)
10041007
Py_CLEAR(ts->st.initial_stub);
10051008
ts->st.initial_stub = initial_stub;
10061009
SLP_SET_CURRENT_FRAME(ts, f);
1007-
slp_current_insert(stmain);
1010+
slp_current_insert(current);
10081011
ts->recursion_depth = recursion_depth;
10091012
ts->st.nesting_level = nesting_level;
10101013
ts->st.serial_last_jump = jump;

Stackless/unittests/test_outside.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ def run():
155155
raise self.result
156156
self.assertIs(self.result, False)
157157

158+
def test_call_from_non_main_tasklet(self):
159+
done = False
160+
def task():
161+
nonlocal done
162+
done = True
163+
164+
stackless.tasklet(task)()
165+
stackless.tasklet(stackless.test_outside)().switch()
166+
self.assertTrue(done)
167+
168+
def test_call_from_non_main_tasklet2(self):
169+
self.assertRaisesRegex(RuntimeError, "main tasklet is still scheduled", stackless.tasklet(stackless.test_outside)().run)
170+
158171

159172
class TestCframe(StacklessTestCase):
160173
n = 100

0 commit comments

Comments
 (0)