elilambnz / react-py

Effortlessly run Python code in your React apps.
https://elilambnz.github.io/react-py
MIT License
232 stars 21 forks source link

Truncating long output #230

Open YoniChechik opened 10 months ago

YoniChechik commented 10 months ago

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)

elilambnz commented 10 months ago

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.

YoniChechik commented 10 months ago

Do a while True loop and print some counter.