import asyncio class SleepTest: @staticmethod async def __sleep_test(): while True: await asyncio.sleep(0) def main(self): try: print(f'{self.__class__.__name__} up') asyncio.run(self.__sleep_test()) except KeyboardInterrupt: print(f'{self.__class__.__name__} down') if __name__ == '__main__': SleepTest().main()