【问题标题】:Pausing a Thread on PyGTK在 PyGTK 上暂停线程
【发布时间】:2018-11-04 07:45:45
【问题描述】:

我有一个按钮,当它被单击时,它会启动一个 GObject 线程,该线程每 2 秒调用一次函数。我想要另一个暂停或停止调用此函数的按钮。谁能引导我走向正确的方向?

使用 Python GTK 3

def on_refreshbutton_clicked(self,widget):
    print("Data..")
    self.th = GObject.timeout_add(2000,self.refresh_screen)

def on_pausebutton_clicked(self,widget):
    print("Paused..")

【问题讨论】:

  • 找到了我的答案。我必须使用 GObject.source_remove(self.th)

标签: python-3.x pygtk gtk3 pygobject gobject


【解决方案1】:

找到了答案。撤销源码!

def on_refreshbutton_clicked(self,widget):
    print("Data..")
    self.th = GObject.timeout_add(2000,self.refresh_screen)

def on_pauseButton_clicked(self, widget):
    print("Paused main screen.")
    GObject.source_remove(self.th)

【讨论】:

  • 另一种解决方案是有一个特殊变量并在refresh_screen 中检查它。如果你想暂停,return GLib.SOURCE_CONTINUE,如果你想停止,return GLib.SOURCE_REMOVE
  • 知道了。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-29
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多