mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 09:45:18 +00:00
hww: fix threading issue in DeviceMgr: enumerate_func needs self.lock
E | gui.qt.main_window.[test_ms_p2wsh_2of3_cc3132_trezort_cc3133] | on_error Traceback (most recent call last): File "...\electrum\electrum\gui\qt\util.py", line 794, in run result = task.task() File "...\electrum\electrum\plugins\hw_wallet\qt.py", line 232, in trigger_pairings devices = devmgr.scan_devices() File "...\electrum\electrum\plugin.py", line 376, in func_wrapper return func(self, *args, **kwargs) File "...\electrum\electrum\plugin.py", line 656, in scan_devices for f in self.enumerate_func: RuntimeError: Set changed size during iteration
This commit is contained in:
parent
bf067f7558
commit
7a4acb05f2
1 changed files with 6 additions and 3 deletions
|
@ -364,7 +364,7 @@ class DeviceMgr(ThreadJob):
|
||||||
# pair.
|
# pair.
|
||||||
self.recognised_hardware = set()
|
self.recognised_hardware = set()
|
||||||
# Custom enumerate functions for devices we don't know about.
|
# Custom enumerate functions for devices we don't know about.
|
||||||
self.enumerate_func = set()
|
self._enumerate_func = set() # Needs self.lock.
|
||||||
# locks: if you need to take multiple ones, acquire them in the order they are defined here!
|
# locks: if you need to take multiple ones, acquire them in the order they are defined here!
|
||||||
self._scan_lock = threading.RLock()
|
self._scan_lock = threading.RLock()
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
|
@ -395,7 +395,8 @@ class DeviceMgr(ThreadJob):
|
||||||
self.recognised_hardware.add(pair)
|
self.recognised_hardware.add(pair)
|
||||||
|
|
||||||
def register_enumerate_func(self, func):
|
def register_enumerate_func(self, func):
|
||||||
self.enumerate_func.add(func)
|
with self.lock:
|
||||||
|
self._enumerate_func.add(func)
|
||||||
|
|
||||||
def create_client(self, device: 'Device', handler: Optional['HardwareHandlerBase'],
|
def create_client(self, device: 'Device', handler: Optional['HardwareHandlerBase'],
|
||||||
plugin: 'HW_PluginBase') -> Optional['HardwareClientBase']:
|
plugin: 'HW_PluginBase') -> Optional['HardwareClientBase']:
|
||||||
|
@ -664,7 +665,9 @@ class DeviceMgr(ThreadJob):
|
||||||
devices = self._scan_devices_with_hid()
|
devices = self._scan_devices_with_hid()
|
||||||
|
|
||||||
# Let plugin handlers enumerate devices we don't know about
|
# Let plugin handlers enumerate devices we don't know about
|
||||||
for f in self.enumerate_func:
|
with self.lock:
|
||||||
|
enumerate_funcs = list(self._enumerate_func)
|
||||||
|
for f in enumerate_funcs:
|
||||||
try:
|
try:
|
||||||
new_devices = f()
|
new_devices = f()
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
|
|
Loading…
Add table
Reference in a new issue