From f265acd2348697170ec7d23af69ebb7af91de0e7 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 31 Aug 2020 22:17:44 +0200 Subject: [PATCH] DeviceMgr.scan_devices: do all scanning on hidapi thread e.g. the trezor custom enumerate function calls hid.enumerate() which is not thread safe (?). see comment on line 330 --- electrum/plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/electrum/plugin.py b/electrum/plugin.py index 75a7962f1..f14aeba82 100644 --- a/electrum/plugin.py +++ b/electrum/plugin.py @@ -682,6 +682,7 @@ class DeviceMgr(ThreadJob): return devices @with_scan_lock + @profiler def scan_devices(self) -> Sequence['Device']: self.logger.info("scanning devices...") @@ -692,8 +693,10 @@ class DeviceMgr(ThreadJob): with self.lock: enumerate_funcs = list(self._enumerate_func) for f in enumerate_funcs: + # custom enumerate functions might use hidapi, so use hid thread to be safe + new_devices_fut = _hid_executor.submit(f) try: - new_devices = f() + new_devices = new_devices_fut.result() except BaseException as e: self.logger.error('custom device enum failed. func {}, error {}' .format(str(f), repr(e)))