Skip to content

Commit

Permalink
hw wallets: fix crashes on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Dec 17, 2023
1 parent bf4934b commit 740016e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion electrum/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def load_plugin(self, name) -> 'BasePlugin':
% (self.gui_name, name))
try:
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
spec.loader.exec_module(module) # note: imports the plugin code in a *different* thread
plugin = module.Plugin(self, self.config, name)
except Exception as e:
raise Exception(f"Error loading {name} plugin: {repr(e)}") from e
Expand Down Expand Up @@ -374,6 +374,16 @@ class HardwarePluginToScan(NamedTuple):
thread_name_prefix='hwd_comms_thread'
)

# hidapi needs to be imported from the main thread. Otherwise, at least on macOS,
# segfaults will follow. (see https://github.com/trezor/cython-hidapi/pull/150#issuecomment-1542391087)
# To keep it simple, let's just import it now, as we are likely in the main thread here.
if threading.current_thread() is not threading.main_thread():
_logger.warning("expected to be in main thread... hidapi will not be safe to use now!")
try:
import hid
except ImportError:
pass


T = TypeVar('T')

Expand Down

0 comments on commit 740016e

Please sign in to comment.