What's idiomatic pyo3 for Rust calling Python?

Pyo3's documentation about "Rust calling Python" is less abundant than about "Extending Python with Rust". My goal is to have a state in Python (class) with repeated calls to Python script methods and functions to update the Python state. My prime problem is coordinating lifetimes between GIL, lock and Python references and objects...

I have the following questions:

  1. The script module has to be loaded (and compiled to bytecode) only once. How can this be done when it can not outlive the GIL's lifetime?
  2. How to call the module's methods and functions by name passing the Python state to be updated?
  3. Which are good example projects (using pyo3) for studying "Rust calling Python" intricacies?


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.