Function pyo3::prepare_freethreaded_python[][src]

pub fn prepare_freethreaded_python()

Prepares the use of Python in a free-threaded context.

If the Python interpreter is not already initialized, this function will initialize it with disabled signal handling (Python will not raise the KeyboardInterrupt exception). Python signal handling depends on the notion of a ‘main thread’, which must be the thread that initializes the Python interpreter.

If both the Python interpreter and Python threading are already initialized, this function has no effect.

Availability

This function is only available when linking against Python distributions that contain a shared library.

This function is not available on PyPy.

Panics

Example

use pyo3::prelude::*;

fn main() {
    pyo3::prepare_freethreaded_python();
    Python::with_gil(|py| {
        py.run("print('Hello World')", None, None)
    });
}