Here is a hack-ish solution to this that I've been using. I've no idea how (in)efficient it is. The idea is to use console.log to dump debugging information to the Interactive Console. This is faster than passing it to the GUI.
Within the Python package, we have to pass it the Console object. I do this with
console = None
console_log = False
def ConsoleLogger(__console__):
global console
global console_log
console = __console__
console_log = True
This declares a global object 'console' wihtin the package and we use ConsoleLogger(console) to initialize it.
Then I define a Python decorator
def debugger (func):
def wrapper(*args, **kwargs):
console.log(f'\nCalling {func.__name__}')
initial_terms = len(args[0])
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
final_terms = len(result)
console.log(f'{initial_terms} --> {final_terms} terms in {end_time-start_time:.3f} s')
return result
return wrapper
Then I can call, e.g.,
debugger(collect_terms)(ex)
to have collect_terms dump its data to the Interactive Console.
Note: the timer only times the actual function, not the debugger wrapper.