File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import random
99import re
1010import sys
11- from threading import Event
1211import traceback
1312import types
1413import 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
You can’t perform that action at this time.
0 commit comments