Plugins: start thread at end of constructor

Don't add jobs twice
This commit is contained in:
Neil Booth 2016-01-24 19:59:58 +09:00
parent 028ab925ed
commit 93e0c72ce2
2 changed files with 5 additions and 7 deletions

View File

@ -330,7 +330,6 @@ if __name__ == '__main__':
if not config.get('offline'):
network = Network(config)
network.start()
plugins.start()
else:
network = None
daemon = Daemon(config, network)
@ -353,7 +352,6 @@ if __name__ == '__main__':
if p == 0:
network = Network(config)
network.start()
plugins.start()
daemon = Daemon(config, network)
if config.get('websocket_server'):
from electrum import websockets

View File

@ -46,11 +46,14 @@ class Plugins(DaemonThread):
self.gui_name = gui_name
self.descriptions = {}
self.device_manager = DeviceMgr()
self.load_plugins()
self.start()
def load_plugins(self):
for loader, name, ispkg in pkgutil.iter_modules([self.pkgpath]):
m = loader.find_module(name).load_module(name)
d = m.__dict__
gui_good = gui_name in d.get('available_for', [])
gui_good = self.gui_name in d.get('available_for', [])
# We register wallet types even if the GUI isn't provided
# otherwise the user gets a misleading message like
# "Unknown wallet type: 2fa"
@ -60,7 +63,7 @@ class Plugins(DaemonThread):
if not gui_good:
continue
self.descriptions[name] = d
if not d.get('requires_wallet_type') and config.get('use_' + name):
if not d.get('requires_wallet_type') and self.config.get('use_' + name):
try:
self.load_plugin(name)
except BaseException as e:
@ -151,9 +154,6 @@ class Plugins(DaemonThread):
return self.plugins[name]
def run(self):
jobs = [job for plugin in self.plugins.values()
for job in plugin.thread_jobs()]
self.add_jobs(jobs)
while self.is_running():
time.sleep(0.1)
self.run_jobs()