From 7a2abbac7665f4a45accf28142f01cc7404b6e08 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 22 Jul 2017 20:26:32 +0100 Subject: [PATCH] defer module calls to threads --- dave/dave.py | 9 ++++++--- dave/modules/speedtest.py | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dave/dave.py b/dave/dave.py index 0ed921a..f521f42 100644 --- a/dave/dave.py +++ b/dave/dave.py @@ -9,7 +9,8 @@ import modules 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 @@ class Dave(irc.IRCClient): if method[1] is not None: # we matched a command - 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: # modules that should always be run regardless of priority - 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": diff --git a/dave/modules/speedtest.py b/dave/modules/speedtest.py index 912ebde..977c107 100644 --- a/dave/modules/speedtest.py +++ b/dave/modules/speedtest.py @@ -4,7 +4,6 @@ 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) -- libgit2 1.7.2