MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / is_free_threaded_python

Function is_free_threaded_python

src/executor/valgrind/helpers/python.rs:5–21  ·  view source on GitHub ↗

Checks if the Python interpreter supports free-threaded mode. Returns true if Python is free-threaded (GIL disabled), false otherwise.

()

Source from the content-addressed store, hash-verified

3/// Checks if the Python interpreter supports free-threaded mode.
4/// Returns true if Python is free-threaded (GIL disabled), false otherwise.
5pub fn is_free_threaded_python() -> bool {
6 // Use sysconfig.get_config_var("Py_GIL_DISABLED") as recommended by Python docs at https://docs.python.org/3/howto/free-threading-python.html#identifying-free-threaded-python
7 let output = Command::new("python")
8 .args([
9 "-c",
10 "import sysconfig; print(sysconfig.get_config_var('Py_GIL_DISABLED') or 0)",
11 ])
12 .output();
13
14 match output {
15 Ok(output) if output.status.success() => {
16 let stdout = String::from_utf8_lossy(&output.stdout);
17 stdout.trim() == "1"
18 }
19 _ => false, // If Python is not available or command fails, assume not free-threaded
20 }
21}

Callers 1

measureFunction · 0.85

Calls 1

argsMethod · 0.80

Tested by

no test coverage detected