1async def application(scope, receive, send): 2 if scope['type'] == 'lifespan': 3 while True: 4 message = await receive() 5 if message['type'] == 'lifespan.startup': 6 await send({"type": "lifespan.startup.failed"}) 7 raise Exception('Exception blah') 8 9 elif message['type'] == 'lifespan.shutdown': 10 await send({'type': 'lifespan.shutdown.complete'}) 11 return 12