diff --git a/modsde.py b/modsde.py index 3e3a39b..996a494 100644 --- a/modsde.py +++ b/modsde.py @@ -38,10 +38,6 @@ class ModsDeChecker(object): self.cj = http.cookiejar.CookieJar() self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cj)) - self.thread = threading.Thread(target=self.mainloop) - self.thread.daemon = True - self.thread.start() - def mainloop(self): while True: unread = self.get_unread_count() diff --git a/statushandler.py b/statushandler.py index bb3e6f8..bb64b74 100644 --- a/statushandler.py +++ b/statushandler.py @@ -3,6 +3,7 @@ import sys import json import urllib.request, urllib.error, urllib.parse +from threading import Thread class Module(object): output = None @@ -23,12 +24,6 @@ class I3statusHandler(object): def register_module(self, module): """Register a new module.""" - # check if module implemented the - # correct functions - #if not hasattr(module, 'output'): - # raise Exception("Module %s does not implement \ - # all the needed functions!".format(module)) - self.modules.append(module) def print_line(self, message): @@ -55,6 +50,12 @@ class I3statusHandler(object): self.print_line(self.read_line()) self.print_line(self.read_line()) + for module in self.modules: + if module.async: + module.thread = Thread(target=module.mainloop) + module.thread.daemon = True + module.thread.start() + while True: line, prefix = self.read_line(), '' diff --git a/thunderbirdnewmail.py b/thunderbirdnewmail.py index 667df9e..b5873b8 100644 --- a/thunderbirdnewmail.py +++ b/thunderbirdnewmail.py @@ -43,10 +43,6 @@ class ThunderbirdMailChecker(object): dbus.mainloop.glib.threads_init() self.context = loop.get_context() - self.thread = threading.Thread(target=self.mainloop) - self.thread.daemon = True - self.thread.start() - def mainloop(self): while True: self.context.iteration(False) @@ -75,4 +71,3 @@ class ThunderbirdMailChecker(object): } else: self.output = None -