Skip to content

Commit

Permalink
Exit with an error if --gil but we failed to get necessary addrs/offs…
Browse files Browse the repository at this point in the history
…ets (#361)

Previously we'd just emit a warning, which is less noticeable; and the result of
a --gil run where without the needed information is going to empty, anyway.
  • Loading branch information
Jongy authored Mar 21, 2021
1 parent 5b87ae2 commit 3322942
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/python_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ pub struct PythonSpy {
pub dockerized: bool
}

fn exit_if_gil(config: &Config, version: &Version, msg: &str) {
if config.gil_only {
eprintln!("Cannot detect GIL holding in version '{}' on the current platform (reason: {})", version, msg);
eprintln!("Please open an issue in https://github.com/benfred/py-spy with the Python version and your platform.");
std::process::exit(1);
}
warn!("Unable to detect GIL usage: {}", msg);
}

impl PythonSpy {
/// Constructs a new PythonSpy object.
pub fn new(pid: Pid, config: &Config) -> Result<PythonSpy, Error> {
Expand Down Expand Up @@ -76,12 +85,12 @@ impl PythonSpy {
addr, offset);
addr as usize + offset
} else {
warn!("Unknown pyruntime.gilstate.tstate_current offset for version {:?}", version);
exit_if_gil(config, &version, "unknown pyruntime.gilstate.tstate_current offset");
0
}
},
None => {
warn!("Failed to find _PyRuntime symbol - won't be able to detect GIL usage");
exit_if_gil(config, &version, "failed to find _PyRuntime symbol");
0
}
}
Expand All @@ -93,7 +102,7 @@ impl PythonSpy {
addr as usize
},
None => {
warn!("Failed to find _PyThreadState_Current symbol - won't be able to detect GIL usage");
exit_if_gil(config, &version, "failed to find _PyThreadState_Current symbol");
0
}
}
Expand Down

0 comments on commit 3322942

Please sign in to comment.