| 1 |
use pyembed::MainPythonInterpreter; |
| 2 |
|
| 3 |
// Include an auto-generated file containing the default |
| 4 |
// `pyembed::PythonConfig` derived by the PyOxidizer configuration file. |
| 5 |
// |
| 6 |
// If you do not want to use PyOxidizer to generate this file, simply |
| 7 |
// remove this line and instantiate your own instance of |
| 8 |
// `pyembed::PythonConfig`. |
| 9 |
include!(env!("PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS")); |
| 10 |
|
| 11 |
fn main() { |
| 12 |
// The following code is in a block so the MainPythonInterpreter is |
| 13 |
// destroyed in an orderly manner, before process exit. |
| 14 |
let code = { |
| 15 |
// Load the default Python configuration as derived by the PyOxidizer |
| 16 |
// config file used at build time. |
| 17 |
let config = default_python_config(); |
| 18 |
|
| 19 |
// Construct a new Python interpreter using that config, handling any |
| 20 |
// errors from construction. |
| 21 |
match MainPythonInterpreter::new(config) { |
| 22 |
Ok(mut interp) => { |
| 23 |
// And run it using the default run configuration as specified |
| 24 |
// by the configuration. If an uncaught Python |
| 25 |
// exception is raised, handle it. |
| 26 |
// This includes the special SystemExit, which is a request to |
| 27 |
// terminate the process. |
| 28 |
interp.run_as_main() |
| 29 |
} |
| 30 |
Err(msg) => { |
| 31 |
eprintln!("{}", msg); |
| 32 |
1 |
| 33 |
} |
| 34 |
} |
| 35 |
}; |
| 36 |
|
| 37 |
// And exit the process according to code execution results. |
| 38 |
std::process::exit(code); |
| 39 |
} |