[英]Python BackgroundScheduler program crashing when ran from another module
I am trying to build a application that will run a bash script every 10 minutes. 我正在尝试构建一个将每10分钟运行一次bash脚本的应用程序。 I am using apscheduler to accomplish this and when i run my code from terminal it works like clock work.
我正在使用apscheduler完成此操作,当我从终端运行代码时,它的工作原理类似于时钟工作。 However when i try to run the code from another module it crashes i suspect that the calling module is waiting for the "schedule" module to finish and then crash when that never happens.
但是,当我尝试从另一个模块运行代码时,它崩溃了,我怀疑调用模块正在等待“时间表”模块完成,然后崩溃,而这永远不会发生。
Error code 错误代码
/bin/bash: line 1: 13613 Killed ( python ) < /tmp/vIZsEfp/26
shell returned 137
Function that calls schedule 调用时间表的功能
def shedual_toggled(self,widget):
prosessSchedular.start_background_checker()
Schedule Program 计划程序
def schedul_check():
"""set up to call prosess checker every 10 mins"""
print "%s check ran" %(counter)
counter =+ 1
app = prosessCheckerv3.call_bash() < calls the bash file
if app == False:
print "error with bash"
return False
else:
prosessCheckerv3.build_snap_shot(app)
def start_background_checker():
scheduler = BackgroundScheduler()
scheduler.add_job(schedul_check, 'interval', minutes=10)
scheduler.start()
while True:
time.sleep(2)
if __name__ == '__main__':
start_background_checker()
this program simply calls another ever 10 mins. 该程序仅调用另一个10分钟。 As a side note i have been trying to stay as far away from multi-threading as possible but if that is required so be it.
顺带一提,我一直在尝试尽可能远离多线程,但是如果需要的话,就这样吧。
Well I managed to figure it out my self. 好吧,我设法弄清楚了自己。 The issue that GTK+ is not thread safe so the timed module need to be either be ran in another thread or else you can realise/enter the thread before/after calling the module.
GTK +不是线程安全的问题,因此需要在另一个线程中运行定时模块,否则您可以在调用模块之前/之后实现/输入该线程。
I just did it like this. 我就是这样做的。
def shedual_toggeld(self,widget):
onOffSwitch = widget.get_active()
""" After main GTK has logicly finished all GUI work run thread on toggel button """
thread = threading.Thread(target=self.call_schedual, args=(onOffSwitch,))
thread.daemon = True
thread.start()
def call_schedual(self, onOffSwitch):
if onOffSwitch == True:
self.sch.start_background_checker()
else:
self.sch.stop_background_checker()
This article goes through it in more detail. 本文将对其进行详细介绍。 Hopefully some one else will find this useful.
希望其他人会发现这很有用。 http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness
http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.