@@ -5,8 +5,9 @@ use std::{
55
66use pyo3:: {
77 types:: { IntoPyDict as _, PyAnyMethods as _, PyModule } ,
8- Bound , Py , PyAny , Python ,
8+ Bound , Py , PyAny , Python , ffi :: c_str ,
99} ;
10+ use std:: ffi:: { CString , CStr } ;
1011
1112use super :: { calc_class, is_notebook, MarketConfig } ;
1213
@@ -49,9 +50,11 @@ impl PyRestBar {
4950 format ! ( "{}{}" , PY_TQDM_PYTHON , PY_BAR )
5051 } ;
5152
53+ let py_script = CString :: new ( py_script. as_str ( ) ) . unwrap ( ) ;
54+
5255 Python :: with_gil ( |py| {
5356 let py_module =
54- PyModule :: from_code_bound ( py, & py_script, "py_file_bar.py" , "py_file_bar" ) ;
57+ PyModule :: from_code ( py, py_script. as_c_str ( ) , c_str ! ( "py_file_bar.py" ) , c_str ! ( "py_file_bar" ) ) ;
5558
5659 if py_module. is_err ( ) {
5760 log:: error!( "py_file_bar tqdm bar class create error" )
@@ -142,8 +145,10 @@ impl PyFileBar {
142145 } ;
143146
144147 Python :: with_gil ( |py| {
148+ let py_script = CString :: new ( py_script. as_str ( ) ) . unwrap ( ) ;
149+
145150 let py_module =
146- PyModule :: from_code_bound ( py, & py_script, "py_file_bar.py" , "py_file_bar" ) ;
151+ PyModule :: from_code ( py, py_script. as_c_str ( ) , c_str ! ( "py_file_bar.py" ) , c_str ! ( "py_file_bar" ) ) ;
147152
148153 if py_module. is_err ( ) {
149154 log:: error!( "py_file_bar tqdm bar class create error" )
@@ -226,11 +231,6 @@ impl PyFileBar {
226231}
227232
228233
229-
230- const PY_RUNNING_BAR : & str = r#"
231-
232- "# ;
233-
234234pub struct PyRunningBar {
235235 bar : Py < PyAny > ,
236236 enable : bool ,
@@ -258,8 +258,10 @@ impl PyRunningBar {
258258 } ;
259259
260260 Python :: with_gil ( |py| {
261+ let py_script = CString :: new ( py_script. as_str ( ) ) . unwrap ( ) ;
262+
261263 let py_module =
262- PyModule :: from_code_bound ( py, & py_script, "py_running_bar.py" , "py_running_bar" ) ;
264+ PyModule :: from_code ( py, & py_script, c_str ! ( "py_running_bar.py" ) , c_str ! ( "py_running_bar" ) ) ;
263265
264266 if py_module. is_err ( ) {
265267 log:: error!( "py progress tqdm bar class create error" )
0 commit comments