Skip to content
\n

Execution output.

\n
Traceback (most recent call last):\n  File \"<embedded>\", line 2, in <module>\n  File \"asyncio\", line 6, in <module>\n  File \"selectors\", line 11, in <module>\nModuleNotFoundError: No module named 'math'\n
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

Hi @youknowone
\nThank you for your fast response. Actually, I could not find example for my case and I found some information from the repo and codes. But I tried to use call_between_rust_and_python.rs as a reference and got another issue.

\n

Cargo.toml:

\n
rustpython = {git = \"http://github.com/rustpython/rustpython.git\", features = [\"stdlib\", \"freeze-stdlib\"]}
\n

The code:

\n
use rustpython::vm::{VirtualMachine, PyResult, stdlib::get_module_inits, compiler};\n\nfn main() -> PyResult<()> {\n    let interp = rustpython::InterpreterConfig::new()\n    .init_stdlib()\n    .interpreter();\n\n\n    interp.enter(|vm| {\n        let scope = vm.new_scope_with_builtins();\n\n        let code_obj = vm\n            .compile(\n                r#\"\nimport asyncio\nprint(\"Hello World!\")\n\"#,\n                compiler::Mode::Exec,\n                \"<embedded>\".to_owned(),\n            )\n            .map_err(|err| vm.new_syntax_error(&err))?;\n\n        if let Err(error) = vm.run_code_obj(code_obj, scope) {\n            vm.print_exception(error);\n        }\n\n        Ok(())\n    })\n}
\n

The output is:

\n
Running `target\\debug\\server.exe\n\nthread 'main' has overflowed its stack\nerror: process didn't exit successfully: `target\\debug\\server.exe` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)\n
\n

I would like to fully embed RustPython in my app. That is the reason I would like to keep freeze-stdlib feature.

","upvoteCount":1,"url":"https://github.com/RustPython/RustPython/discussions/4699#discussioncomment-5335418"}}}
Discussion options

You must be logged in to vote

Hi @youknowone
Thank you for your fast response. Actually, I could not find example for my case and I found some information from the repo and codes. But I tried to use call_between_rust_and_python.rs as a reference and got another issue.

Cargo.toml:

rustpython = {git = "http://github.com/rustpython/rustpython.git", features = ["stdlib", "freeze-stdlib"]}

The code:

use rustpython::vm::{VirtualMachine, PyResult, stdlib::get_module_inits, compiler};

fn main() -> PyResult<()> {
    let interp = rustpython::InterpreterConfig::new()
    .init_stdlib()
    .interpreter();


    interp.enter(|vm| {
        let scope = vm.new_scope_with_builtins();

        let code_obj = vm
            .compile(…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@youknowone
Comment options

@erhanbaris
Comment options

@youknowone
Comment options

@erhanbaris
Comment options

Answer selected by erhanbaris
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants