diff --git a/lbrynet/core/LBRYcrdWallet.py b/lbrynet/core/LBRYcrdWallet.py index 22326b315..bfead86df 100644 --- a/lbrynet/core/LBRYcrdWallet.py +++ b/lbrynet/core/LBRYcrdWallet.py @@ -52,8 +52,7 @@ class LBRYcrdWallet(object): def make_connection(): if self.start_lbrycrdd is True: self._start_daemon() - logging.info("Trying to connect to %s", self.rpc_conn_string) - self.rpc_conn = AuthServiceProxy(self.rpc_conn_string) + self._get_info() logging.info("Connected!") def start_manage(): @@ -66,6 +65,10 @@ class LBRYcrdWallet(object): return d def stop(self): + + def log_stop_error(err): + logging.error("An error occurred stopping the wallet. %s", err.getTraceback()) + self.stopped = True # If self.next_manage_call is None, then manage is currently running or else # start has not been called, so set stopped and do nothing else. @@ -74,8 +77,10 @@ class LBRYcrdWallet(object): self.next_manage_call = None d = self.manage() + d.addErrback(log_stop_error) if self.start_lbrycrdd is True: - d.addBoth(lambda _: self._stop_daemon()) + d.addCallback(lambda _: self._stop_daemon()) + d.addErrback(log_stop_error) return d def manage(self): @@ -248,6 +253,18 @@ class LBRYcrdWallet(object): def get_new_address(self): return threads.deferToThread(self._get_new_address) + def _get_rpc_conn(self): + return AuthServiceProxy(self.rpc_conn_string) + + def _catch_connection_error(f): + def w(*args): + try: + return f(*args) + except socket.error: + raise ValueError("Unable to connect to an lbrycrd server. Make sure an lbrycrd server " + + "is running and that this application can connect to it.") + return w + def _start_daemon(self): if os.name == "nt": @@ -264,7 +281,7 @@ class LBRYcrdWallet(object): tries = 0 while tries < 5: try: - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() rpc_conn.getinfo() break except (socket.error, JSONRPCException): @@ -329,8 +346,9 @@ class LBRYcrdWallet(object): dl.addCallback(handle_checks) return dl + @_catch_connection_error def _check_expected_balance(self, expected_balance): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() logging.info("Checking balance of address %s", str(expected_balance[1])) balance = rpc_conn.getreceivedbyaddress(expected_balance[1]) logging.debug("received balance: %s", str(balance)) @@ -341,7 +359,7 @@ class LBRYcrdWallet(object): logging.info("Trying to send payments, if there are any to be sent") def do_send(payments): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() rpc_conn.sendmany("", payments) payments_to_send = {} @@ -357,24 +375,34 @@ class LBRYcrdWallet(object): logging.info("There were no payments to send") return defer.succeed(True) + @_catch_connection_error + def _get_info(self): + rpc_conn = self._get_rpc_conn() + return rpc_conn.getinfo() + + @_catch_connection_error def _get_wallet_balance(self): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() return rpc_conn.getbalance("") + @_catch_connection_error def _get_new_address(self): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() return rpc_conn.getnewaddress() + @_catch_connection_error def _get_value_for_name(self, name): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() return rpc_conn.getvalueforname(name) + @_catch_connection_error def _claim_name(self, name, value, amount): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() return str(rpc_conn.claimname(name, value, amount)) + @_catch_connection_error def _rpc_stop(self): - rpc_conn = AuthServiceProxy(self.rpc_conn_string) + rpc_conn = self._get_rpc_conn() rpc_conn.stop() self.lbrycrdd.wait() diff --git a/lbrynet/core/Session.py b/lbrynet/core/Session.py index 9bff46fde..aeaa3ac25 100644 --- a/lbrynet/core/Session.py +++ b/lbrynet/core/Session.py @@ -230,7 +230,11 @@ class LBRYSession(object): self.rate_limiter.tick() d1 = self.blob_manager.setup() d2 = self.wallet.start() - return defer.DeferredList([d1, d2], fireOnOneErrback=True) + + dl = defer.DeferredList([d1, d2], fireOnOneErrback=True, consumeErrors=True) + + dl.addErrback(lambda err: err.value.subFailure) + return dl def _unset_upnp(self): diff --git a/lbrynet/lbrynet_console/ConsoleControl.py b/lbrynet/lbrynet_console/ConsoleControl.py index 5d7566516..782dce528 100644 --- a/lbrynet/lbrynet_console/ConsoleControl.py +++ b/lbrynet/lbrynet_console/ConsoleControl.py @@ -27,7 +27,7 @@ class ConsoleControl(basic.LineReceiver): self.sendLine(response) def show_error(err): - self.sendLine(err.getTraceback()) + self.sendLine(err.getErrorMessage()) if self.current_handler is None: try: diff --git a/lbrynet/lbrynet_console/LBRYConsole.py b/lbrynet/lbrynet_console/LBRYConsole.py index 0b3dbd150..d15ae3892 100644 --- a/lbrynet/lbrynet_console/LBRYConsole.py +++ b/lbrynet/lbrynet_console/LBRYConsole.py @@ -86,8 +86,13 @@ class LBRYConsole(): d.addCallback(lambda _: self._load_plugins()) d.addCallback(lambda _: self._setup_server()) d.addCallback(lambda _: self._start_controller()) + d.addErrback(self._show_start_error) return d + def _show_start_error(self, error): + print error.getErrorMessage() + return error + def shut_down(self): """Stop the session, all currently running streams, and stop the server""" d = self.session.shut_down() @@ -348,10 +353,13 @@ class LBRYConsole(): def _shut_down(self): self.plugin_manager = None - d1 = self.lbry_file_metadata_manager.stop() - d1.addCallback(lambda _: self.lbry_file_manager.stop()) - d2 = self.stop_server() - dl = defer.DeferredList([d1, d2]) + ds = [] + if self.lbry_file_metadata_manager is not None: + d = self.lbry_file_metadata_manager.stop() + d.addCallback(lambda _: self.lbry_file_manager.stop()) + ds.append(d) + ds.append(self.stop_server()) + dl = defer.DeferredList(ds) return dl @@ -451,5 +459,8 @@ def launch_lbry_console(): conf_dir=conf_dir, data_dir=data_dir) d = task.deferLater(reactor, 0, console.start) + + d.addErrback(lambda _: reactor.stop()) + reactor.addSystemEventTrigger('before', 'shutdown', console.shut_down) reactor.run() \ No newline at end of file diff --git a/lbrynet/lbrynet_downloader_gui/LBRYDownloader.py b/lbrynet/lbrynet_downloader_gui/LBRYDownloader.py index ffd8475b8..702c9fc98 100644 --- a/lbrynet/lbrynet_downloader_gui/LBRYDownloader.py +++ b/lbrynet/lbrynet_downloader_gui/LBRYDownloader.py @@ -381,11 +381,10 @@ class LBRYDownloader(object): def show_stream_status(downloader): total_bytes = downloader.get_total_bytes() bytes_left_to_download = downloader.get_bytes_left_to_download() - bytes_left_to_output = downloader.get_bytes_left_to_output() points_paid = payment_rate_manager.points_paid payment_rate = payment_rate_manager.get_effective_min_blob_data_payment_rate() points_remaining = 1.0 * bytes_left_to_download * payment_rate / 2**20 - stream_frame.show_progress(total_bytes, bytes_left_to_download, bytes_left_to_output, + stream_frame.show_progress(total_bytes, bytes_left_to_download, points_paid, points_remaining) def show_finished(arg, downloader): diff --git a/lbrynet/lbrynet_downloader_gui/StreamFrame.py b/lbrynet/lbrynet_downloader_gui/StreamFrame.py index 93e436bfa..ea9ec969e 100644 --- a/lbrynet/lbrynet_downloader_gui/StreamFrame.py +++ b/lbrynet/lbrynet_downloader_gui/StreamFrame.py @@ -99,7 +99,6 @@ class StreamFrame(object): self.status_label = None self.name_label = None self.bytes_downloaded_label = None - self.bytes_outputted_label = None self.button_frame = None self.download_buttons = [] self.option_frames = [] @@ -111,6 +110,7 @@ class StreamFrame(object): self.remaining_cost_description = None self.cost_label = None self.remaining_cost_label = None + self.progress_frame = None def cancel(self): if self.cancel_func is not None: @@ -344,9 +344,9 @@ class StreamFrame(object): self.show_options_button.config(image=self.hide_options_picture) self.options_frame.grid(sticky=tk.W + tk.E, row=3) - def show_progress(self, total_bytes, bytes_left_to_download, bytes_left_to_output, points_paid, + def show_progress(self, total_bytes, bytes_left_to_download, points_paid, points_remaining): - if self.bytes_outputted_label is None: + if self.bytes_downloaded_label is None: self.remove_download_buttons() self.button_frame.destroy() for option, frame in self.option_frames: @@ -354,8 +354,17 @@ class StreamFrame(object): self.options_frame.destroy() self.show_options_button.destroy() + self.progress_frame = ttk.Frame(self.outer_button_frame, style="F.TFrame") + self.progress_frame.grid(row=0, column=0, sticky=tk.W, pady=(0, 8)) + + self.bytes_downloaded_label = ttk.Label( + self.progress_frame, + text="" + ) + self.bytes_downloaded_label.grid(row=0, column=0) + self.cost_frame = ttk.Frame(self.outer_button_frame, style="F.TFrame") - self.cost_frame.grid(row=0, column=0, sticky=tk.W+tk.N, pady=(0, 12)) + self.cost_frame.grid(row=1, column=0, sticky=tk.W, pady=(0, 7)) self.cost_label = ttk.Label( self.cost_frame, @@ -365,25 +374,13 @@ class StreamFrame(object): self.cost_label.grid(row=0, column=1, padx=(1, 0)) self.outer_button_frame.grid_columnconfigure(2, weight=0, uniform="") - self.bytes_outputted_label = ttk.Label( - self.file_name_frame, - text="" - ) - self.bytes_outputted_label.grid(row=0, column=0) - - self.bytes_downloaded_label = ttk.Label( - self.file_name_frame, - text="" - ) - self.bytes_downloaded_label.grid(row=0, column=1) - - if self.bytes_outputted_label.winfo_exists(): - self.bytes_outputted_label.config( - text=self.get_formatted_stream_size(total_bytes - bytes_left_to_output) + " / " - ) if self.bytes_downloaded_label.winfo_exists(): + percent_done = 0 + if total_bytes > 0: + percent_done = 100.0 * (total_bytes - bytes_left_to_download) / total_bytes + percent_done_string = locale.format_string(" (%.2f%%)", percent_done) self.bytes_downloaded_label.config( - text=self.get_formatted_stream_size(total_bytes - bytes_left_to_download) + " / " + text=self.get_formatted_stream_size(total_bytes - bytes_left_to_download) + percent_done_string ) if self.cost_label.winfo_exists(): total_points = points_remaining + points_paid @@ -392,8 +389,6 @@ class StreamFrame(object): grouping=True)) def show_download_done(self, total_points_paid): - if self.bytes_outputted_label is not None and self.bytes_outputted_label.winfo_exists(): - self.bytes_outputted_label.destroy() if self.bytes_downloaded_label is not None and self.bytes_downloaded_label.winfo_exists(): self.bytes_downloaded_label.destroy() if self.cost_label is not None and self.cost_label.winfo_exists():