wasmer-python icon indicating copy to clipboard operation
wasmer-python copied to clipboard

Unable to use print after using "instance.exports._start()"

Open yusuf8ahmed opened this issue 4 years ago • 3 comments

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?

yusuf8ahmed avatar Feb 20 '21 13:02 yusuf8ahmed

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 :-).

Hywan avatar Feb 22 '21 08:02 Hywan

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.

yusuf8ahmed avatar Mar 26 '21 16:03 yusuf8ahmed

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.

Hywan avatar Jul 13 '21 10:07 Hywan