react-py icon indicating copy to clipboard operation
react-py copied to clipboard

Truncating long output

Open YoniChechik opened this issue 2 years ago • 2 comments

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)

YoniChechik avatar Aug 21 '23 13:08 YoniChechik

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.

elilambnz avatar Aug 27 '23 22:08 elilambnz

Do a while True loop and print some counter.

YoniChechik avatar Aug 27 '23 23:08 YoniChechik