Python协同程序停止整个程序

Python协同程序停止整个程序,python,pygame,python-asyncio,coroutine,Python,Pygame,Python Asyncio,Coroutine,我试图创建一个函数,它会等待一段时间,但time.sleep()不适合这样做,因为它会停止整个程序。我决定使用与wait asyncio.sleep()的协同程序,但即使这样也会停止整个程序!我可能做错了什么,因为我通常不使用python中的协同程序,但如果您知道修复此问题的方法,请提供帮助 class myclass: async def MyCoroutine(self): value = random.randint(3,7) await async

我试图创建一个函数,它会等待一段时间,但time.sleep()不适合这样做,因为它会停止整个程序。我决定使用与wait asyncio.sleep()的协同程序,但即使这样也会停止整个程序!我可能做错了什么,因为我通常不使用python中的协同程序,但如果您知道修复此问题的方法,请提供帮助

class myclass:
    async def MyCoroutine(self):
        value = random.randint(3,7)
        await asyncio.sleep(value)
        print("done")
    
    def myfunction(self):
        self.exit = False
        while not self.exit:
            asyncio.run(self.MyCoroutine())
卸下
()