File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -997,6 +997,30 @@ class MyKeyboardInterrupt(KeyboardInterrupt):
997997        self .assertIsNotNone (exc )
998998        self .assertListEqual (gc .get_referrers (exc ), no_other_refs ())
999999
1000+     async  def  test_cancels_task_if_created_during_creation (self ):
1001+         ran  =  False 
1002+         class  MyError (Exception ):
1003+             pass 
1004+ 
1005+         try :
1006+             async  with  asyncio .TaskGroup () as  tg :
1007+                 async  def  third_task ():
1008+                     raise  MyError ("third task failed" )
1009+ 
1010+                 async  def  second_task ():
1011+                     nonlocal  ran 
1012+                     tg .create_task (third_task ())
1013+                     with  self .assertRaises (asyncio .CancelledError ):
1014+                         await  asyncio .sleep (0 )  # eager tasks cancel here 
1015+                         await  asyncio .sleep (0 )  # lazy tasks cancel here 
1016+                     ran  =  True 
1017+ 
1018+                 tg .create_task (second_task ())
1019+         except* MyError  as  excs :
1020+             exc  =  excs .exceptions [0 ]
1021+ 
1022+         self .assertIsInstance (exc , MyError )
1023+         self .assertTrue (ran )
10001024
10011025if  __name__  ==  "__main__" :
10021026    unittest .main ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments