Skip to content

Commit 8fa2cac

Browse files
committed
Add unit test
1 parent f69f706 commit 8fa2cac

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/test/test_asyncio/test_tasks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for tasks.py."""
22

33
import collections
4+
from concurrent.futures import thread
45
import contextlib
56
import contextvars
67
import gc
@@ -3680,6 +3681,18 @@ def task_factory(loop, coro):
36803681
(loop, context), kwargs = callback.call_args
36813682
self.assertEqual(context['exception'], exc_context.exception)
36823683

3684+
def test_run_coroutine_threadsafe_and_cancel(self):
3685+
async def target():
3686+
# self.loop.run_in_executor(None, _in_another_thread)
3687+
thread_future = asyncio.run_coroutine_threadsafe(self.add(1, 2), self.loop)
3688+
await asyncio.sleep(0)
3689+
3690+
thread_future.cancel()
3691+
await asyncio.sleep(0)
3692+
3693+
self.loop.run_until_complete(target())
3694+
self.assertEqual(0, len(self.loop._ready))
3695+
36833696

36843697
class SleepTests(test_utils.TestCase):
36853698
def setUp(self):

0 commit comments

Comments
 (0)