Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with an error if --gil but we failed to get necessary addrs/offsets #361

Merged
merged 3 commits into from
Mar 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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