Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python SDK Error with Polling not implemented for clocks yet #5318

Open
miraclejzd opened this issue Dec 29, 2024 · 2 comments
Open

Python SDK Error with Polling not implemented for clocks yet #5318

miraclejzd opened this issue Dec 29, 2024 · 2 comments
Assignees

Comments

@miraclejzd
Copy link

I am trying to write a python program to run wasm file with Wasmer Python SDK. Here is my source code of wasm file:

use std::fs::OpenOptions;
use std::io::{Write};
use std::thread::sleep;
use std::time::{Duration, SystemTime};
use rand::Rng;
use chrono::TimeZone;

#[no_mangle]
fn main() {
    println!("Begin");
    loop {
        let content = get_content();

        append_to_file("file.txt", &content);

        sleep(Duration::from_secs(10));
    }
}

fn append_to_file(filename: &str, content: &str) {
    let file = OpenOptions::new()
        .write(true)
        .append(true)
        .create(true)
        .open(filename)
        .expect("Failed to open file for appending");

    let mut file = std::io::BufWriter::new(file);
    writeln!(file, "{}", content).expect("Failed to write to file");
    println!("log: {}", content);
}

fn get_content() -> String {
    let timestamp = SystemTime::now()
        .duration_since(SystemTime::UNIX_EPOCH)
        .expect("Failed to get timestamp")
        .as_secs();

    let formatted_timestamp = chrono::Utc.timestamp(timestamp as i64, 0).to_string();

    let random_number = rand::thread_rng().gen_range(0..100);

    format!("{}     {}", formatted_timestamp, random_number)
}

And I compile it to wasm file with the command:

cargo build --target wasm32-wasi --release

When I run it with wasmer run cronjob.wasm, it works well:

$ wasmer run cronjob.wasm
Begin
log: 2024-12-29 15:49:34 UTC     38
log: 2024-12-29 15:49:44 UTC     81
...

But when I use the Python SDK, it fails with this panic:

$ python bench.py
Begin
log: 2024-12-29 13:57:53 UTC     17
thread '<unnamed>' panicked at 'not implemented: Polling not implemented for clocks yet', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/wasmer-wasi-2.1.1/src/syscalls/mod.rs:2388:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "bench.py", line 42, in <module>
    instance.exports._start()
pyo3_runtime.PanicException: not implemented: Polling not implemented for clocks yet

And here is my bench.py:

from wasmer import engine, wasi, Store, Module, ImportObject, Instance
from wasmer_compiler_cranelift import Compiler
import os

__dir__ = os.path.dirname(os.path.realpath(__file__))
wasm_bytes = open(__dir__ + '/cronjob.wasm', 'rb').read()

store = Store(engine.Universal(Compiler))

module = Module(store, wasm_bytes)

wasi_env = \
    wasi.StateBuilder('cronjob').finalize()

import_object = wasi_env.generate_import_object(store, wasi_version)

instance = Instance(module, import_object)

instance.exports._start()

Is there something wrong with the Python SDK?

@xdoardo
Copy link
Contributor

xdoardo commented Jan 2, 2025

Hello, thanks for the report. We think that the issue might be that the Python SDK has not been updated in a while. We have plans to update it, and I'll mention it in this issue once we get it done.

@xdoardo xdoardo self-assigned this Jan 2, 2025
@miraclejzd
Copy link
Author

Hello, thanks for the report. We think that the issue might be that the Python SDK has not been updated in a while. We have plans to update it, and I'll mention it in this issue once we get it done.

Thanks for replying. I am looking forward to it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants