Skip to content

Commit f061b1d

Browse files
committed
Revert "Run test in another thread"
1 parent 670e875 commit f061b1d

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

Lib/test/test_asyncio/test_tasks.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import random
99
import re
1010
import sys
11-
from threading import Event
1211
import traceback
1312
import types
1413
import unittest
@@ -3682,21 +3681,15 @@ def task_factory(loop, coro):
36823681
self.assertEqual(context['exception'], exc_context.exception)
36833682

36843683
def test_run_coroutine_threadsafe_and_cancel(self):
3685-
target_started = Event()
3686-
async def _target():
3687-
target_started.set()
3688-
await asyncio.sleep(0.1)
3689-
return 1
3684+
async def target():
3685+
# self.loop.run_in_executor(None, _in_another_thread)
3686+
thread_future = asyncio.run_coroutine_threadsafe(self.add(1, 2), self.loop)
3687+
await asyncio.sleep(0)
36903688

3691-
def _in_thread():
3692-
thread_future = asyncio.run_coroutine_threadsafe(_target(), self.loop)
3693-
# wait target started then cancel
3694-
target_started.wait()
36953689
thread_future.cancel()
3696-
_ = self.loop.run_in_executor(None, _in_thread)
3690+
await asyncio.sleep(0)
36973691

3698-
# start main loop to do things
3699-
self.loop.run_until_complete(asyncio.sleep(0.05))
3692+
self.loop.run_until_complete(target())
37003693
self.assertEqual(0, len(self.loop._ready))
37013694

37023695

0 commit comments

Comments
 (0)