File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ def load_plugin(self, name) -> 'BasePlugin':
140
140
% (self .gui_name , name ))
141
141
try :
142
142
module = importlib .util .module_from_spec (spec )
143
- spec .loader .exec_module (module )
143
+ spec .loader .exec_module (module ) # note: imports the plugin code in a *different* thread
144
144
plugin = module .Plugin (self , self .config , name )
145
145
except Exception as e :
146
146
raise Exception (f"Error loading { name } plugin: { repr (e )} " ) from e
@@ -374,6 +374,16 @@ class HardwarePluginToScan(NamedTuple):
374
374
thread_name_prefix = 'hwd_comms_thread'
375
375
)
376
376
377
+ # hidapi needs to be imported from the main thread. Otherwise, at least on macOS,
378
+ # segfaults will follow. (see https://github.com/trezor/cython-hidapi/pull/150#issuecomment-1542391087)
379
+ # To keep it simple, let's just import it now, as we are likely in the main thread here.
380
+ if threading .current_thread () is not threading .main_thread ():
381
+ _logger .warning ("expected to be in main thread... hidapi will not be safe to use now!" )
382
+ try :
383
+ import hid
384
+ except ImportError :
385
+ pass
386
+
377
387
378
388
T = TypeVar ('T' )
379
389
You can’t perform that action at this time.
0 commit comments