tlnbase: print exceptions from main_loop - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit e906e6e90af706ccc7a727e6c4dbd0655816d635 DIR parent b9ca9724453df6443dc81e9ad191b48fa289119e HTML Author: Janus <ysangkok@gmail.com> Date: Thu, 12 Apr 2018 14:51:25 +0200 lnbase: print exceptions from main_loop Diffstat: M lib/lnbase.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) --- DIR diff --git a/lib/lnbase.py b/lib/lnbase.py t@@ -4,6 +4,7 @@ Derived from https://gist.github.com/AdamISZ/046d05c156aaeb56cc897f85eecb3eb8 """ +import traceback import itertools import json from collections import OrderedDict t@@ -332,20 +333,23 @@ class Peer(PrintError): # self.send_message(gen_msg('open_channel', funding_satoshis=funding_sat, push_msat=push_msat)) async def main_loop(self): - self.reader, self.writer = await asyncio.open_connection(self.host, self.port) - await self.handshake() - # send init - self.send_message(gen_msg("init", gflen=0, lflen=0)) - # read init - msg = await self.read_message() - self.process_message(msg) - # initialized - self.init_message_received_future.set_result(msg) - # loop - while True: - self.ping_if_required() + try: + self.reader, self.writer = await asyncio.open_connection(self.host, self.port) + await self.handshake() + # send init + self.send_message(gen_msg("init", gflen=0, lflen=0)) + # read init msg = await self.read_message() self.process_message(msg) + # initialized + self.init_message_received_future.set_result(msg) + # loop + while True: + self.ping_if_required() + msg = await self.read_message() + self.process_message(msg) + except: + traceback.print_exc() # close socket self.print_error('closing lnbase') self.writer.close()