I有一个Python应用程序,其中包含要通过间隔调用的函数。 def call_repeat(Interval,func, *args,** kwargs): 停止= threading.event() lock = threading.lock()#l ...

问题描述 投票:0回答:0
'func'这是要调用的函数。我将在300秒,900秒和3600秒间隔内将三个“弹药”。

整个Python应用程序在Raspberry Pi4 Ubuntu系统上运行了几个月,没有任何问题。 现在,我决定将Raspberry放到开发系统,使用Ubuntu创建基于Intel的服务器,然后移动Python应用程序。 现在,300秒600秒间隔调用可行,但是在第二次等待间隔后不会进行3600秒间隔调用,而不会进行任何错误消息。

我尝试了Python调度程序的另一种方法:
def call_repeatedly(interval, func, *args, **kwargs):
    scheduler = sched.scheduler(time.time, time.sleep)
    def loop():
        func(*args, **kwargs)
        scheduler.enter(interval, 1, loop)
    scheduler.enter(interval, 1, loop)
    threading.Thread(target=scheduler.run, daemon=True).start()

this一直持续到午夜,然后3600秒再次呼唤死亡。 我想,那可能是Intel N100芯片中的PowerSave模式,它不小心停止了螺纹呼叫,将Intel芯片设置为民意调查(没有动力节省),但没有运气。问题仍然存在。 300秒和600秒运行,但在某个时候死亡的3600秒。 我看到的唯一一件事是,所有三个呼叫都在整个小时(3600秒)重合。但是,为什么要在较弱的覆盆子Pi 4上工作,而在Intel N100中不使用?

trory替换

time.sleep()

而不是

sched.scheduler
以避免对调度程序库的依赖。 
time.sleep()

在长时间间隔内可能更可靠,因为它不依赖于系统级的时间处理:

def call_repeatedly(interval, func, *args, **kwargs): def loop(): while True: func(*args, **kwargs) time.sleep(interval) threading.Thread(target=loop, daemon=True).start()

python ubuntu python-multithreading raspberry-pi4
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.