URI: 
       tseparate Network and Plugins - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 74a9e2296c43320c18893d0cefd78e3cbdf0b9fb
   DIR parent f651742f86168c40a1fedb7c1d523ed4db25a51d
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Thu,  3 Dec 2015 11:18:10 +0100
       
       separate Network and Plugins
       
       Diffstat:
         M electrum                            |      17 +++++++++--------
         M lib/network.py                      |       8 ++------
         M lib/plugins.py                      |      24 ++++++++++++------------
         M plugins/exchange_rate/exchange_rat… |       2 +-
       
       4 files changed, 24 insertions(+), 27 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -346,15 +346,15 @@ if __name__ == '__main__':
            # daemon is not running
            if cmd_name == 'gui':
                if not config.get('offline'):
       -            network = Network(config, plugins)
       +            network = Network(config)
                    network.start()
       +            plugins.start()
                else:
                    network = None
                gui = init_gui(config, network, plugins)
       -        server = Daemon(config, network, gui)
       -        server.start()
       +        daemon = Daemon(config, network, gui)
       +        daemon.start()
                gui.main()
       -        server.stop()
                sys.exit(0)
        
            elif cmd_name == 'daemon':
       t@@ -365,16 +365,17 @@ if __name__ == '__main__':
                elif subcommand == 'start':
                    p = os.fork()
                    if p == 0:
       -                network = Network(config, plugins)
       +                network = Network(config)
                        network.start()
       -                server = Daemon(config, network)
       +                plugins.start()
       +                daemon = Daemon(config, network)
                        if config.get('websocket_server'):
                            from electrum import websockets
                            websockets.WebSocketServer(config, network).start()
                        if config.get('requests_dir'):
                            util.check_www_dir(config.get('requests_dir'))
       -                server.start()
       -                server.join()
       +                daemon.start()
       +                daemon.join()
                    else:
                        print_stderr("starting daemon (PID %d)"%p)
                        sys.exit(0)
   DIR diff --git a/lib/network.py b/lib/network.py
       t@@ -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)
       t@@ -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:
       t@@ -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
       t@@ -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):
   DIR diff --git a/lib/plugins.py b/lib/plugins.py
       t@@ -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)
       t@@ -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()
   DIR diff --git a/plugins/exchange_rate/exchange_rate.py b/plugins/exchange_rate/exchange_rate.py
       t@@ -265,7 +265,7 @@ class FxPlugin(BasePlugin, ThreadJob):
                return [self]
        
            def run(self):
       -        # This runs from the network thread which catches exceptions
       +        # This runs from the plugins thread which catches exceptions
                if self.timeout <= time.time():
                    self.timeout = time.time() + 150
                    self.exchange.update(self.ccy)