Python 中的多线程转发器
我有一个小中继器,下面不断结束,如何修复更稳定的崩溃,而不是停止运行...... 我会向图形用户界面添加一个心跳以查看它是否仍在运行。在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这会运行 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?
似乎你需要 join() 来等待启动线程
seems you need join() to wait the start thread