RSS: Do no block commands calling while loading a feed.

This commit is contained in:
Valentin Lorentz 2014-10-14 20:59:00 +00:00
parent e676cc284b
commit 1650860032
2 changed files with 23 additions and 8 deletions

View File

@ -63,6 +63,18 @@ addConverter('feedName', get_feedName)
announced_headlines_filename = \
conf.supybot.directories.data.dirize('RSS_announced.flat')
def only_one_at_once(f):
lock = [False]
def newf(*args, **kwargs):
if lock[0]:
return
lock[0] = True
try:
f(*args, **kwargs)
finally:
lock[0] = False
return newf
class Feed:
__slots__ = ('url', 'name', 'data', 'last_update', 'entries',
'etag', 'modified', 'initial',
@ -129,7 +141,6 @@ def save_announces_db(db, fd):
json.dump(dict((name, list(entries)) for (name, entries) in db), fd)
class RSS(callbacks.Plugin):
"""This plugin is useful both for announcing updates to RSS feeds in a
channel, and for retrieving the headlines of RSS feeds via command. Use
@ -230,7 +241,7 @@ class RSS(callbacks.Plugin):
def __call__(self, irc, msg):
self.__parent.__call__(irc, msg)
self.update_feeds()
threading.Thread(target=self.update_feeds).start()
##################
@ -274,6 +285,7 @@ class RSS(callbacks.Plugin):
if self.is_expired(feed):
self.update_feed(feed)
@only_one_at_once
def update_feeds(self):
announced_feeds = set()
for irc in world.ircs:

View File

@ -242,12 +242,15 @@ class SupyHTTPRequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
if 'Content-Type' not in self.headers:
self.headers['Content-Type'] = 'application/x-www-form-urlencoded'
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
if self.headers['Content-Type'] == 'application/x-www-form-urlencoded':
form = cgi.FieldStorage(
fp=self.rfile,
headers=self.headers,
environ={'REQUEST_METHOD':'POST',
'CONTENT_TYPE':self.headers['Content-Type'],
})
else:
form = self.rfile.read()
self.do_X('doPost', form=form)
def do_HEAD(self):