1
0

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
This commit is contained in:
SomberNight
2020-08-31 22:17:44 +02:00
parent 6d86f4dc18
commit f265acd234

View File

@@ -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)))