defer module calls to threads
Diff
dave/dave.py | 9 +++++++--
dave/modules/speedtest.py | 1 -
2 files changed, 6 insertions(+), 4 deletions(-)
@@ -9,7 +9,8 @@
import re
import config
import datetime
from twisted.internet.threads import deferToThread
from twisted.internet import reactor
from twisted.internet.threads import deferToThreadPool
class Dave(irc.IRCClient):
@@ -75,12 +76,14 @@
if method[1] is not None:
method[1](self, method[2], nick, channel)
deferToThreadPool(reactor, reactor.getThreadPool(), method[1], self,
method[2], nick, channel)
if not (hasattr(method[1], "dont_always_run") and method[1].dont_always_run):
for m in run:
m[0](self, m[1], nick, channel)
deferToThreadPool(reactor, reactor.getThreadPool(), m[0], self,
m[1], nick, channel)
def irc_unknown(self, prefix, command, params):
if command == "INVITE":
@@ -1,10 +1,9 @@
from requests import get
from bs4 import BeautifulSoup
import dave.module
from twisted.words.protocols.irc import assembleFormattedText, attributes as A
@dave.module.match(r'https?://(?:www\.|beta\.)?speedtest\.net/(?:my-)?result/([0-9]+)(?:.png)?')
@dave.module.priority(dave.module.Priority.HIGHEST)
@dave.module.dont_always_run_if_run()
def speedtest(bot, args, sender, source):
res = get("http://www.speedtest.net/result/{}".format(args[0]), timeout=3)