wasmer-python
wasmer-python copied to clipboard
Unable to use print after using "instance.exports._start()"
Thanks for the bug report!
Describe the bug
After setting up WASI and trying the method "instance.exports._start()" all output to the terminal fails including print and sys. write.out also, I couldn't find any docs on the _start method?
Steps to reproduce
code to reproduce:
store = Store(engine.JIT(Compiler))
module = Module(store, open(path, 'rb').read())
wasi_version = wasi.get_version(module, strict=True)
wasi_env = wasi.StateBuilder('test-program').finalize()
import_object = wasi_env.generate_import_object(store, wasi_version)
instance = Instance(module, import_object)
instance.exports._start()
print(f"\Main function ended") # would not print?
Hello,
Maybe your Wasm module is running a loop, and thus the print statement after instance.exports._start() isn't executed yet?
WASI defines the _start function as an equivalent to the main function in C, Java, Rust etc. So when you have a Rust program like:
fn main() {
println!("Hello, World!");
}
Once compiled to Wasm, to start the program, you need to call the exported function _start.
I can't help you here without knowing what your Wasm module does :-).
Hello,
Got a little busy with school work but the code is now working, I can print after exports._start() by using a try-except block.
i just have a few more questions:
- whenever I
._start(), it always raises 'RuntimeError: RuntimeError: WASI exited with code: 0' why ? - how can I make
exports._start()return True if the main function runs successfully otherwise return false.
Can you try with a recent version of wasmer-python please? Because I cannot reproduce your error when the _start function always returns an RuntimeError.