代码之家  ›  专栏  ›  技术社区  ›  Flávio Amieiro

Python中有没有替代gobject.timeout\u add()的方法?

  •  0
  • Flávio Amieiro  · 技术社区  · 16 年前

    我正在使用gobject.timeout\u add()显示项目中的计时器( dojotools ).

    我想知道是否有其他方法可以实现相同的结果,但是没有gobject依赖性。

    2 回复  |  直到 16 年前
        1
  •  2
  •   lunixbochs    16 年前

    你可以用一个线程配合time.sleep(interval)来达到同样的效果。

    import thread, time
    
    def timer():
        while True:
            time.sleep(1)
            # do something here
    
    thread.start_new_thread(timer, ())
    
        2
  •  1
  •   Michael Petrotta user3140870    13 年前

    after() 功能。
    这样可以避免睡眠造成的阻塞。