react-py
react-py copied to clipboard
Truncating long output
Long output that changes fast can cause slowness in the client side. I sugest that the package will have some num lines trunction threshold.
it can be easily implemented in the usePython hook:
proxy((msg: string) => {
// Suppress messages that are not useful for the user
if (suppressedMessages.includes(msg)) {
return
}
setOutput((prev) => [...prev, msg]) // <-------------- count num lines here and stop setting output if above TH
}),
proxy(({ id, version }) => {
setRunnerId(id)
console.debug('Loaded pyodide version:', version)
}),
allPackages
)
}
The var numMaxOutputLines can be set in the usePython (-1 default to no truncation)
Can you please provide an example of when this might be useful? There is already a timeout option to kill the worker if execution takes too long. Since execution is done in a worker, this shouldn't impact the UI thread.
Do a while True loop and print some counter.