pyo3

Function prepare_freethreaded_python

Source
pub fn prepare_freethreaded_python()
Expand description

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

If the Python interpreter is not already initialized, this function will initialize it with signal handling disabled (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 the Python interpreter is already initialized, this function has no effect.

This function is unavailable under PyPy because PyPy cannot be embedded in Rust (or any other software). Support for this is tracked on the PyPy issue tracker.

§Examples

use pyo3::prelude::*;

pyo3::prepare_freethreaded_python();
Python::with_gil(|py| py.run_bound("print('Hello World')", None, None))