在python的主线程中定期调用函数
我知道如何在单独的线程中定期调用函数:在python的主线程中定期调用函数,python,multithreading,Python,Multithreading,我知道如何在单独的线程中定期调用函数: def main_loop(): cefpython.MessageLoopWork() # do something threading.Timer(0.01, main_loop).start() main_loop() 但是我如何在主线程中实现它(必须从主线程调用cefpython.MessageLoopWork()) 在中,它是使用wxTimer完成的,但我不想使用wxpython: class MyApp(wx.App):
def main_loop():
cefpython.MessageLoopWork() # do something
threading.Timer(0.01, main_loop).start()
main_loop()
但是我如何在主线程中实现它(必须从主线程调用cefpython.MessageLoopWork()
)
在中,它是使用wxTimer
完成的,但我不想使用wxpython
:
class MyApp(wx.App):
[...]
def CreateTimer(self):
self.timer = wx.Timer(self, self.timerID)
self.timer.Start(10) # 10ms
wx.EVT_TIMER(self, self.timerID, self.OnTimer)
def OnTimer(self, event):
cefpython.MessageLoopWork()
好的,您必须使用围绕事件循环构建的库。除了wxpython之外,cefpython文档也有。我不想使用大的GUI框架,但我可能已经解决了我的问题,这要感谢(虽然它没有回答这个问题)