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

Function is_free_threaded_python

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

Returns true if any Python interpreter the benchmark command could resolve to is free-threaded: PATH `python`/`python3`, `$VIRTUAL_ENV`, the working directory's `.venv`, and the interpreter `uv` selects for `$UV_PYTHON`. `uv` downloads a requested interpreter lazily, so when `$UV_PYTHON` is not installed yet the request string itself decides.

(working_directory: Option<&Path>)

Source from the content-addressed store, hash-verified

15/// `uv` downloads a requested interpreter lazily, so when `$UV_PYTHON` is not installed
16/// yet the request string itself decides.
17pub fn is_free_threaded_python(working_directory: Option<&Path>) -> bool {
18 let cwd = working_directory.unwrap_or(Path::new("."));
19
20 let mut candidates: Vec<PathBuf> = vec![PathBuf::from("python"), PathBuf::from("python3")];
21 if let Some(venv) = std::env::var_os("VIRTUAL_ENV") {
22 candidates.push(Path::new(&venv).join("bin/python"));
23 }
24 candidates.push(cwd.join(".venv/bin/python"));
25 if let Some(request) = std::env::var_os("UV_PYTHON") {
26 match uv_python_find(&request, cwd) {
27 Some(python) => candidates.push(python),
28 None if is_free_threaded_request(&request.to_string_lossy()) => {
29 debug!("free-threaded Python requested via UV_PYTHON={request:?}");
30 return true;
31 }
32 None => {}
33 }
34 }
35
36 candidates.into_iter().any(|python| {
37 let free_threaded = is_gil_disabled(&python);
38 if free_threaded {
39 debug!("detected free-threaded Python: {}", python.display());
40 }
41 free_threaded
42 })
43}
44
45fn is_gil_disabled(python: &Path) -> bool {
46 let Ok(output) = Command::new(python)

Callers 1

measureFunction · 0.85

Calls 3

uv_python_findFunction · 0.85
is_free_threaded_requestFunction · 0.85
is_gil_disabledFunction · 0.85

Tested by

no test coverage detected