Python 中的多线程转发器

发布于 2024-09-24 08:47:47 字数 610 浏览 4 评论 0原文

我有一个小中继器,下面不断结束,如何修复更稳定的崩溃,而不是停止运行...... 我会向图形用户界面添加一个心跳以查看它是否仍在运行。在 Wxpthon 中,我的菜单栏变为空白或白色。

 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()
                time.sleep(invl)

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):
                dothis()

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

々眼睛长脚气 2024-10-01 08:47:47

这会运行 7000 次迭代。因此,如果您的运行时间约为 7000*300 秒,它“完全按照编码工作”:-) 但是,线程数或您在 FetchUpdates 中执行的操作可能会出现问题。停止时是否有回溯?是否已达到用户限制?

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?

脱离于你 2024-10-01 08:47:47

似乎你需要 join() 来等待启动线程

 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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文