Web Worker postMessage failing using numpy
See original GitHub issuepyodide version: 0.17.0 i’m using pyodide in my react app. I use the off-the-shelf webworker provided from the example. It more or less works, however, there’s one “interesting” caveat that I thought I’d bring to the attention of the maintainers:
say I have the following python code:
import pandas as pd
pd.DataFrame([1,2,3])
If I open up a python REPL or even use the Pyodide Terminal Emulator
I get the output:
0
0 1
1 2
2 3
However, whenever
const results = await self.pyodide.runPythonAsync(python);
self.postMessage({ results })
gets called, I get the following:
failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': [object Object] could not be cloned
the googles and the overflowing stack lead me to believe it might have something to do with this but seems like a red herring.
After banging my head on the keyboard for a while I realized you could sort of work around this by doing:
self.postMessage({results: `${results}`})
except if we change the initial example to:
import pandas as pd
pd.DataFrame([1,2,3])
print("SOMETHING")
now result is undefined. I can get the SOMETHING
by redirecting stdout and returning that, but overall, this is kind of not an ideal situation.
I tried splitting the statements line-wise and iterating (ala a repl), but that doesn’t work either.
I did a fair amount of diligence on this and realized this might be solved by https://github.com/pyodide/pyodide/pull/1563, but it’d be great if someone could provide a working example of how this should work or maybe point me in the direction of what i’m doing wrong as i’m basically doing exactly what the docs said and can’t get this seemingly trivial example to work.
maybe update the docs? happy to provide more context + an example.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
But only if you have a Python on the other side of the connection too.
Thanks @hoodmane - that was indeed the problem and using
.toString()
if the results areisPyProxy()
is working for my test cases.