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.


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

This function is not available on PyPy.


  • If the Python interpreter is initialized but Python threading is not, a panic occurs. It is not possible to safely access the Python runtime unless the main thread (the thread which originally initialized Python) also initializes threading.


use pyo3::prelude::*;

fn main() {
    Python::with_gil(|py| {"print('Hello World')", None, None)