Skip to content

Commit d6330bc

Browse files
author
Anselm Kruis
committed
Stackless issue python#199: stackless call "asyncio._CTask"
Remove an unused static function, add test cases and change-log.
1 parent 06cb695 commit d6330bc

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

Modules/_asynciomodule.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,23 +2540,19 @@ task_step_impl_stackless(PyObject *retval, long *step, PyObject **ob1, PyObject
25402540
static PyStacklessFunctionDeclarationObject task_step_impl_declaration = {
25412541
PyObject_HEAD_INIT(NULL)
25422542
task_step_impl_stackless,
2543-
"task_step_impl_stackless"
2543+
"_task_step_impl_stackless"
25442544
};
2545-
#endif
25462545

25472546
static PyObject *
2548-
task_step_impl(TaskObj *task, PyObject *exc)
2547+
task_step_impl_part1(TaskObj *task, PyObject *exc, int *failed)
25492548
{
2550-
#ifdef STACKLESS
2551-
return PyStackless_CallFunction(&task_step_impl_declaration, Py_None,
2552-
(PyObject *)task, exc, NULL, 0, NULL);
2553-
}
2549+
STACKLESS_GETARG();
2550+
#else /* #ifdef STACKLESS */
25542551

25552552
static PyObject *
2556-
task_step_impl_part1(TaskObj *task, PyObject *exc, int *failed)
2553+
task_step_impl(TaskObj *task, PyObject *exc)
25572554
{
2558-
#endif
2559-
STACKLESS_GETARG();
2555+
#endif /* #ifdef STACKLESS */
25602556
int res;
25612557
int clear_exc = 0;
25622558
PyObject *result = NULL;

Stackless/changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://github.com/stackless-dev/stackless/issues/199
13+
Enable stackless calls of coroutines wrapped in "asyncio._CTask", if
14+
soft-switching is enabled. Now asyncio runs coroutines stackless.
15+
16+
- https://github.com/stackless-dev/stackless/issues/196
17+
Stackless can now pickle coroutine_wrapper objects.
18+
1219
- https://github.com/stackless-dev/stackless/issues/190
1320
Silently ignore attempts to close a running generator, coroutine or
1421
asynchronous generator. This avoids spurious error messages, if such an

Stackless/unittests/test_generator.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pickle
77
import contextlib
88
import sys
9+
import asyncio
910

1011
from support import test_main # @UnusedImport
1112
from support import StacklessTestCase, captured_stderr
@@ -242,5 +243,48 @@ def test_finalizer(self):
242243
self._test_finalizer(pf_dump, pf_load)
243244

244245

246+
class TestStacklessOperations(StacklessTestCase):
247+
def assertLevel(self, expected=0):
248+
self.assertTrue(stackless.current.alive)
249+
if stackless.enable_softswitch(None):
250+
self.assertEqual(stackless.current.nesting_level, expected)
251+
else:
252+
self.assertGreater(stackless.current.nesting_level, expected)
253+
254+
@types.coroutine
255+
def coro1yield(self):
256+
yield
257+
258+
async def coro(self):
259+
self.assertLevel()
260+
await self.coro1yield()
261+
self.assertLevel()
262+
await self.coro1yield()
263+
self.assertLevel()
264+
265+
def _test_asyncio(self, task_class):
266+
async def test():
267+
try:
268+
await self.coro()
269+
finally:
270+
loop.stop()
271+
272+
asyncio.set_event_loop(asyncio.new_event_loop())
273+
self.addCleanup(asyncio.set_event_loop, None)
274+
loop = asyncio.get_event_loop()
275+
task = task_class(test())
276+
asyncio.ensure_future(task)
277+
try:
278+
loop.run_forever()
279+
finally:
280+
loop.close()
281+
282+
def test_asyncio_PyTask(self):
283+
self._test_asyncio(asyncio.tasks._PyTask)
284+
285+
def test_asyncio_CTask(self):
286+
self._test_asyncio(asyncio.tasks._CTask)
287+
288+
245289
if __name__ == '__main__':
246290
unittest.main()

0 commit comments

Comments
 (0)