Python没有离开睡眠

问题描述

我写了一个小程序,应该在特定时间收集数据并在记录时间之间休眠。

为此,我正在使用datetime模块。等待函数调用方式如下:

d = dt.datetime.Now()

debug_mode = True
open_hour = 9
open_minute = 32

if d.weekday() > 4:
    day_shift = 7 - d.weekday() # Calculates the day shift till monday
    target = d.replace(day=d.day+day_shift,hour=open_hour,minute=open_minute,second=0)
    
    wait_till(d,target,debug_mode,"Weekend")

这是我的“ wait_till”功能

def wait_till(d,wait_message=""):
    ''' 
    Function waits the time betweend d and target. 
    
    d : current datetime [datetime]
    target: target datetime [datetime]

    debug_mode: debugging active [True/False]
    wait_message: Message for the debug file [string]
    '''

    if debug_mode:
        debug_fops(d,"{}. Waiting for: {} seconds".format(wait_message,(target-d).total_seconds())) 
        # debug_fops writes the string and some extra info into a debug-file
        # is being called and the seconds count is correct
        
    time.sleep((target-d).total_seconds())
    
    if debug_mode:
        d = dt.datetime.Now()
        debug_fops(d,"Sleep ended") # never happens

程序运行得很好...但是time.sleep()似乎永远不会离开。 我没有收到任何错误消息,也不知道那里发生了什么...。

你们中的任何一个都知道那里可能会发生什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)