electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 6ccd83397ceb5885c3b60ada55679c62a3c5cb16
parent d1f11f5fe94264f85a6c03afd2c43edb6134aeab
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 14 Sep 2018 23:01:28 +0200

fx: asyncio.Event is not thread-safe; also the 'timeout' field was removed

Diffstat:
Melectrum/exchange_rate.py | 20++++++++++++--------
Melectrum/gui/qt/main_window.py | 5++---
2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py @@ -443,13 +443,13 @@ class FxThread(ThreadJob): self.ccy_combo = None self.hist_checkbox = None self.cache_dir = os.path.join(config.path, 'cache') - self.trigger = asyncio.Event() - self.trigger.set() + self._trigger = asyncio.Event() + self._trigger.set() self.set_exchange(self.config_exchange()) make_dir(self.cache_dir) def set_proxy(self, trigger_name, *args): - self.trigger.set() + self._trigger.set() def get_currencies(self, h): d = get_exchanges_by_ccy(h) @@ -471,11 +471,11 @@ class FxThread(ThreadJob): async def run(self): while True: try: - await asyncio.wait_for(self.trigger.wait(), 150) + await asyncio.wait_for(self._trigger.wait(), 150) except concurrent.futures.TimeoutError: pass else: - self.trigger.clear() + self._trigger.clear() if self.is_enabled(): if self.show_history(): self.exchange.get_historical_rates(self.ccy, self.cache_dir) @@ -487,7 +487,7 @@ class FxThread(ThreadJob): def set_enabled(self, b): self.config.set_key('use_exchange_rate', bool(b)) - self.trigger.set() + self.trigger_update() def get_history_config(self): return bool(self.config.get('history_rates')) @@ -520,9 +520,13 @@ class FxThread(ThreadJob): def set_currency(self, ccy): self.ccy = ccy self.config.set_key('currency', ccy, True) - self.trigger.set() # Because self.ccy changes + self.trigger_update() self.on_quotes() + def trigger_update(self): + if self.network: + self.network.asyncio_loop.call_soon_threadsafe(self._trigger.set) + def set_exchange(self, name): class_ = globals().get(name, BitcoinAverage) self.print_error("using exchange", name) @@ -531,7 +535,7 @@ class FxThread(ThreadJob): self.exchange = class_(self.on_quotes, self.on_history) # A new exchange means new fx quotes, initially empty. Force # a quote refresh - self.trigger.set() + self.trigger_update() self.exchange.read_historical_rates(self.ccy, self.cache_dir) def on_quotes(self): diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py @@ -2962,8 +2962,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): update_exchanges() self.history_list.refresh_headers() if self.fx.is_enabled() and checked: - # reset timeout to get historical rates - self.fx.timeout = 0 + self.fx.trigger_update() update_history_capgains_cb() def on_history_capgains(checked): @@ -3025,7 +3024,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): d.exec_() if self.fx: - self.fx.timeout = 0 + self.fx.trigger_update() self.alias_received_signal.disconnect(set_alias_color)