Browse Source
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
patch-4
SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
1 changed files with
4 additions and
1 deletions
-
electrum/plugin.py
|
@ -682,6 +682,7 @@ class DeviceMgr(ThreadJob): |
|
|
return devices |
|
|
return devices |
|
|
|
|
|
|
|
|
@with_scan_lock |
|
|
@with_scan_lock |
|
|
|
|
|
@profiler |
|
|
def scan_devices(self) -> Sequence['Device']: |
|
|
def scan_devices(self) -> Sequence['Device']: |
|
|
self.logger.info("scanning devices...") |
|
|
self.logger.info("scanning devices...") |
|
|
|
|
|
|
|
@ -692,8 +693,10 @@ class DeviceMgr(ThreadJob): |
|
|
with self.lock: |
|
|
with self.lock: |
|
|
enumerate_funcs = list(self._enumerate_func) |
|
|
enumerate_funcs = list(self._enumerate_func) |
|
|
for f in enumerate_funcs: |
|
|
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: |
|
|
try: |
|
|
new_devices = f() |
|
|
new_devices = new_devices_fut.result() |
|
|
except BaseException as e: |
|
|
except BaseException as e: |
|
|
self.logger.error('custom device enum failed. func {}, error {}' |
|
|
self.logger.error('custom device enum failed. func {}, error {}' |
|
|
.format(str(f), repr(e))) |
|
|
.format(str(f), repr(e))) |
|
|