URI: 
       tlightning: separate thread for publish transaction - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 6ab8badb615db8d30d3631f1d3fbc6562bf6b7c7
   DIR parent 277e5be229dd9baa7b055200c7f75dfd37197aaf
  HTML Author: Janus <ysangkok@gmail.com>
       Date:   Mon, 19 Mar 2018 16:42:03 +0100
       
       lightning: separate thread for publish transaction
       
       Diffstat:
         M lib/lightning.py                    |      21 +++++++++++++++++----
       
       1 file changed, 17 insertions(+), 4 deletions(-)
       ---
   DIR diff --git a/lib/lightning.py b/lib/lightning.py
       t@@ -478,12 +478,21 @@ def signOutputRaw(tx, signDesc):
        async def PublishTransaction(json):
            req = rpc_pb2.PublishTransactionRequest()
            json_format.Parse(json, req)
       -    global NETWORK
       +    global NETWORK, globLock
            tx = transaction.Transaction(binascii.hexlify(req.tx).decode("utf-8"))
       -    suc, has = NETWORK.broadcast(tx)
       +    def target(tx, NETWORK, globLock):
       +        globLock.acquire()
       +        try:
       +          res = NETWORK.broadcast(tx)
       +          print("PUBLISH TRANSACTION IN SEPARATE THREAD PRODUCED", res)
       +        except:
       +          traceback.print_exc()
       +        finally:
       +          globLock.release()
       +    threading.Thread(target=target, args=(tx, NETWORK, globLock)).start()
            m = rpc_pb2.PublishTransactionResponse()
       -    m.success = suc
       -    m.error = str(has) if not suc else ""
       +    m.success = True
       +    m.error = ""
            if m.error:
                print("PublishTransaction", m.error)
                if "Missing inputs" in m.error:
       t@@ -724,7 +733,10 @@ async def readJson(reader):
                except TimeoutError:
                    continue
        
       +globLock = None
       +
        async def readReqAndReply(obj, writer, netAndWalLock):
       +    global globLock
            methods = [
            # SecretKeyRing
            DerivePrivKey,
       t@@ -753,6 +765,7 @@ async def readReqAndReply(obj, writer, netAndWalLock):
                    if method.__name__ == obj["method"]:
                        params = obj["params"][0]
                        print("calling method", obj["method"], "with", params)
       +                globLock = netAndWalLock
                        netAndWalLock.acquire()
                        if asyncio.iscoroutinefunction(method):
                            result = await method(params)