开发者

Multithreaded repeater in Python

I have small repeater Below that keeps ending, How can fix so more stable from crashes, and not stop running.... I would I add a heartbeat to the gui to see that its still running. In Wxpthon, my menu bar goes blank or white.

 def TimerSetup():
        import threading, time
        invl = 300

        def dothis():
            try:
                FetchUpdates()
            except Exception as e:
                pass

        class Repeat(threading.Thread):
            def run(self):
           开发者_StackOverflow社区     dothis()

        if __name__ == '__main__':
            for x in range(7000):
                thread = Repeat(name = "Thread-%d" % (x + 1))
                thread.start()
                time.sleep(invl)


This runs for 7000 iterations. So if your runtime is at about 7000*300 s, it "works exactly as coded" :-) However, possibly the number of threads or the things you do in FetchUpdates could be a problem. Is there any traceback when it stops? Are reaching a user limit?


seems you need join() to wait the start thread

 def TimerSetup():
        import threading, time
        invl = 300

        def dothis():
            try:
                FetchUpdates()
            except Exception as e:
                pass

        class Repeat(threading.Thread):
            def run(self):
                dothis()

        if __name__ == '__main__':
            for x in range(7000):
                thread = Repeat(name = "Thread-%d" % (x + 1))
                thread.start()
                thread.join()
                time.sleep(invl)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜