Execution output.
\nTraceback (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'\nHi @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.
Cargo.toml:
\nrustpython = {git = \"http://github.com/rustpython/rustpython.git\", features = [\"stdlib\", \"freeze-stdlib\"]}The code:
\nuse 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}The output is:
\nRunning `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)\nI 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"}}}-
|
Hi all Here is my development environment.
Also, reproduction code: use rustpython_vm as vm;
use rustpython_vm::VirtualMachine;
fn init_vm(vm: &mut VirtualMachine) {
vm.add_frozen(rustpython_pylib::FROZEN_STDLIB);
}
fn main() -> vm::PyResult<()> {
vm::Interpreter::with_init(Default::default(), init_vm).enter(|vm| {
let scope = vm.new_scope_with_builtins();
let code_obj = vm
.compile(
r#"
import asyncio
print("Hello World!")
"#,
vm::compiler::Mode::Exec,
"<embedded>".to_owned(),
)
.map_err(|err| vm.new_syntax_error(&err))?;
if let Err(error) = vm.run_code_obj(code_obj, scope) {
vm.print_exception(error);
}
Ok(())
})
}Execution output. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, would you tell me which example did you use as reference? I'd like to update outdated documents or examples. I recommend to use |
Beta Was this translation helpful? Give feedback.
-
|
Hi @youknowone 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(
r#"
import asyncio
print("Hello World!")
"#,
compiler::Mode::Exec,
"<embedded>".to_owned(),
)
.map_err(|err| vm.new_syntax_error(&err))?;
if let Err(error) = vm.run_code_obj(code_obj, scope) {
vm.print_exception(error);
}
Ok(())
})
}The output is: I would like to fully embed RustPython in my app. That is the reason I would like to keep freeze-stdlib feature. |
Beta Was this translation helpful? Give feedback.
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:
The code: