From 411ee049d557fc22e6f3959f866d59ec2dd32443 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 22 Feb 2014 17:06:32 +0100 Subject: news: timeout bug fix --- news/newsbot.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'news') diff --git a/news/newsbot.py b/news/newsbot.py index 899c5dd2..b24a86e4 100644 --- a/news/newsbot.py +++ b/news/newsbot.py @@ -175,8 +175,8 @@ class RssBot(asybot): self.sendall(entry.title + ' ' + shorturl) self.oldnews.append(entry.link) self.lastnew = datetime.now() - except: - print(self.nickname + ': rss timeout occured') + except Exception as e: + print(str(datetime.now().hour) + ':' + str(datetime.now().minute) + ' ' + self.nickname + ': ' + str(e)) sleep(self.to) def shortenurl(self, url): @@ -193,7 +193,10 @@ class RssBot(asybot): self.send_msg(target, feed.title + ' ' + self.shortenurl(feed.link)) def sendall(self, string): - self.send_msg(self.channels, string) + try: + self.send_msg(self.channels, string) + except Exception as e: + print(self.nickname + ': failed sending all to ' + str(self.channels) + ' because of ' + str(e)); def send_msg(self, target, string): if self.connected: @@ -209,9 +212,9 @@ class RssBot(asybot): else: self.reconnect() while not self.connected: - sleep(3) - print('waiting for reconnect') - self.send_msg(string) + sleep(10) + print(self.nickname + ' waiting for reconnect') + self.send_msg(target, string) def on_invite(self, prefix, command, params, rest): for chan in rest.split(): @@ -237,5 +240,12 @@ for line in lines: bot.start_rss() bots[linear[0]] = bot -th = threading.Thread(target=loop) +def thread_handler(): + while True: + try: + loop() + except Exception as e: + print('ohoh ' + e) + +th = threading.Thread(target=thread_handler) th.start() -- cgit v1.2.3