separate Network and Plugins
This commit is contained in:
@@ -135,7 +135,7 @@ class Network(util.DaemonThread):
|
||||
stop()
|
||||
"""
|
||||
|
||||
def __init__(self, config=None, plugins=None):
|
||||
def __init__(self, config=None):
|
||||
if config is None:
|
||||
config = {} # Do not use mutables as default values!
|
||||
util.DaemonThread.__init__(self)
|
||||
@@ -193,9 +193,6 @@ class Network(util.DaemonThread):
|
||||
self.socket_queue = Queue.Queue()
|
||||
self.start_network(deserialize_server(self.default_server)[2],
|
||||
deserialize_proxy(self.config.get('proxy')))
|
||||
self.plugins = plugins
|
||||
if self.plugins:
|
||||
self.plugins.set_network(self)
|
||||
|
||||
def register_callback(self, callback, events):
|
||||
with self.lock:
|
||||
@@ -354,6 +351,7 @@ class Network(util.DaemonThread):
|
||||
def set_proxy(self, proxy):
|
||||
self.proxy = proxy
|
||||
if proxy:
|
||||
self.print_error('setting proxy', proxy)
|
||||
proxy_mode = proxy_modes.index(proxy["mode"]) + 1
|
||||
socks.setdefaultproxy(proxy_mode, proxy["host"], int(proxy["port"]))
|
||||
socket.socket = socks.socksocket
|
||||
@@ -750,8 +748,6 @@ class Network(util.DaemonThread):
|
||||
self.process_pending_sends()
|
||||
|
||||
self.stop_network()
|
||||
if self.plugins:
|
||||
self.plugins.set_network(None)
|
||||
self.print_error("stopped")
|
||||
|
||||
def on_header(self, i, header):
|
||||
|
||||
@@ -21,15 +21,17 @@ import sys
|
||||
import os
|
||||
import imp
|
||||
import pkgutil
|
||||
import time
|
||||
|
||||
from util import *
|
||||
from i18n import _
|
||||
from util import profiler, PrintError
|
||||
from util import profiler, PrintError, DaemonThread
|
||||
|
||||
class Plugins(PrintError):
|
||||
class Plugins(DaemonThread):
|
||||
|
||||
@profiler
|
||||
def __init__(self, config, is_local, gui_name):
|
||||
DaemonThread.__init__(self)
|
||||
if is_local:
|
||||
find = imp.find_module('plugins')
|
||||
plugins = imp.load_module('electrum_plugins', *find)
|
||||
@@ -116,16 +118,14 @@ class Plugins(PrintError):
|
||||
x += (lambda: self.wallet_plugin_loader(config, name),)
|
||||
wallet.wallet_types.append(x)
|
||||
|
||||
def set_network(self, network):
|
||||
if network != self.network:
|
||||
jobs = [job for plugin in self.plugins.values()
|
||||
for job in plugin.thread_jobs()]
|
||||
if self.network:
|
||||
self.network.remove_jobs(jobs)
|
||||
self.network = network
|
||||
if network:
|
||||
network.add_jobs(jobs)
|
||||
|
||||
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()
|
||||
self.print_error("stopped")
|
||||
|
||||
|
||||
hook_names = set()
|
||||
|
||||
Reference in New Issue
Block a user