如何在python中不睡觉的情况下跟踪时间?

2024-05-16 04:13:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何在一段时间后不使用sleep函数来播放.wav文件。实际上,我想知道是否有一种方法可以在Python中跟踪时间,这样,在15秒之后,我就可以在不暂停代码的情况下播放一个声音。

# checks if I should play the sound or not and, sets the variable

def Tyler(self):
    if self.started == 1:
        if self.isTaiwan == 0:
            if self.myListNames[self.current_player_id / 3].lower() == "tyler":
                self.isTyler = 1
            else:
                self.isTyler = 0

self.Tyler()

if self.isTyler == 1:
    time.sleep(6)
    winsound.PlaySound("tyler.wav", winsound.SND_ASYNC)

# This is where I would want to check to see 
# if some time has passed and the conditions haven't changed.

Tags: and文件theto方法函数selfif