summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2014-01-07 17:10:33 +0100
committerlassulus <lassulus@googlemail.com>2014-01-07 17:10:33 +0100
commit91c2d7a73e6fb10c7eeee8e850c18feb143f3b3a (patch)
tree5fbe817de90ca15c92300b15020adc7ee97e03c1
parentbf8e9d0c833efed489bb5c920fa859b123dd75bf (diff)
ircbot: no more zombie bots
-rwxr-xr-xircbot/rssbot.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/ircbot/rssbot.py b/ircbot/rssbot.py
index 07843e07..531e50c5 100755
--- a/ircbot/rssbot.py
+++ b/ircbot/rssbot.py
@@ -1,7 +1,8 @@
#!/usr/bin/python
import irc.bot
+from irc.client import IRC
import feedparser
-import _thread
+import threading
import math
import re
import subprocess
@@ -23,13 +24,21 @@ class RssBot(irc.bot.SingleServerIRCBot):
self.lastnew = datetime.now()
self.url_shortener = url_shortener
+ def better_loop(timeout=0.2):
+ while self.loop:
+ self.ircobj.process_once(timeout)
+ self.ircobj.process_forever = better_loop
+
+
def start(self):
- self.upd_loop = _thread.start_new_thread(self.updateloop, ())
- self.bot = _thread.start_new_thread(irc.bot.SingleServerIRCBot.start, (self,))
+ self.upd_loop = threading.Thread(target=self.updateloop)
+ self.bot = threading.Thread(target=irc.bot.SingleServerIRCBot.start, args=(self,))
+ self.upd_loop.start()
+ self.bot.start()
def stop(self):
+ self.ircobj.disconnect_all()
self.loop = False
- self.disconnect()
def updateloop(self):
try:
@@ -71,6 +80,7 @@ class RssBot(irc.bot.SingleServerIRCBot):
sleep(1)
else:
self.connection.reconnect()
+ sleep(1)
self.send(string)
def on_invite(self, connection, event):