| 41 | |
| 42 | impl PyNode { |
| 43 | pub fn new( |
| 44 | instance_name: String, |
| 45 | args: &toml::value::Table, |
| 46 | params: &RegistryNodeParams, |
| 47 | ) -> PyNode { |
| 48 | let mut inputs = HashMap::new(); |
| 49 | let mut outputs = HashMap::new(); |
| 50 | for port in ¶ms.inputs { |
| 51 | let (k, v) = parse(port); |
| 52 | inputs.insert(k, v); |
| 53 | } |
| 54 | for port in ¶ms.outputs { |
| 55 | let (k, v) = parse(port); |
| 56 | outputs.insert(k, v); |
| 57 | } |
| 58 | let imp = Python::with_gil(|py| -> _ { |
| 59 | let pyargs = toml2dict(py, args).expect("convert toml to python dict fault"); |
| 60 | match params.code.call1(py, (instance_name.as_str(), pyargs)) { |
| 61 | Err(err) => { |
| 62 | err.print(py); |
| 63 | panic!("parse python code fault"); |
| 64 | } |
| 65 | Ok(ret) => ret, |
| 66 | } |
| 67 | }); |
| 68 | PyNode { |
| 69 | inputs, |
| 70 | outputs, |
| 71 | imp, |
| 72 | name: params.name.clone(), |
| 73 | exclusive: params.exclusive, |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | async fn initialize(&mut self, res: ResourceCollection) { |
| 78 | Python::with_gil(|py| -> PyResult<()> { |