Account for removal of aynchio.Tasks.all_tasks
As we still support 3.5..3.7, we need to catch the case that asyncio.get_running_loop and asyncio.all_tasks are not yet available. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
		
							
								
								
									
										10
									
								
								kas/kas.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								kas/kas.py
									
									
									
									
									
								
							@@ -84,8 +84,16 @@ def _atexit_handler():
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
        Waits for completion of the event loop
 | 
					        Waits for completion of the event loop
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        loop = asyncio.get_running_loop()
 | 
				
			||||||
 | 
					        pending = asyncio.all_tasks(loop)
 | 
				
			||||||
 | 
					    except RuntimeError:
 | 
				
			||||||
 | 
					        # no running loop anymore, nothing to do
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    except AttributeError:
 | 
				
			||||||
 | 
					        # for Python < 3.7
 | 
				
			||||||
        loop = asyncio.get_event_loop()
 | 
					        loop = asyncio.get_event_loop()
 | 
				
			||||||
    pending = asyncio.Task.all_tasks()
 | 
					        pending = asyncio.Task.all_tasks(loop)
 | 
				
			||||||
    if not loop.is_closed():
 | 
					    if not loop.is_closed():
 | 
				
			||||||
        loop.run_until_complete(asyncio.gather(*pending))
 | 
					        loop.run_until_complete(asyncio.gather(*pending))
 | 
				
			||||||
        loop.close()
 | 
					        loop.close()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user