Skip to content

Commit

Permalink
Log run_hook main thread warning via warnings module so it only appea…
Browse files Browse the repository at this point in the history
…rs once
  • Loading branch information
mhsmith committed Dec 31, 2020
1 parent b87f129 commit 07be799
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions electroncash/plugins.py
Expand Up @@ -31,6 +31,7 @@
import threading
import time
import traceback
from warnings import warn
import zipimport

from collections import namedtuple, defaultdict
Expand Down Expand Up @@ -581,12 +582,11 @@ def myhook(self, arg1, arg2):

this_thread = threading.current_thread()
if this_thread is not threading.main_thread():
msg = (f'Warning: run_hook "{name}" being called from outside the main'
f' thread (thr: {this_thread.name}) may lead to undefined'
' behavior. Please use util.do_in_main_thread to call run_hook'
' if the hook in question does not return any results.'
'\nTraceback:\n') + ''.join(traceback.format_stack())
print_error(msg)
warn(f'run_hook "{name}" being called from outside the main'
f' thread (thr: {this_thread.name}) may lead to undefined'
' behavior. Please use util.do_in_main_thread to call run_hook'
' if the hook in question does not return any results.',
stacklevel=2)
f_list = hooks.get(name)
if not f_list:
# short-circuit return: most of the time this code path is taken
Expand Down

0 comments on commit 07be799

Please sign in to comment.