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

时间:2015-06-26 21:41:24

标签: python python-2.7 tkinter sleep

我想知道如何在不使用.wav功能一段时间后播放sleep文件。基本上,我想知道是否有办法在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.

1 个答案:

答案 0 :(得分:0)

from time import time
def delay(secs):
    init_time = time()
    while time() < init_time+secs: pass

这不会使用睡眠,但是它是相似的。仍然使用时间模块

相关问题