Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed May 7, 2024
1 parent 069764a commit bae454e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
64 changes: 50 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ remoteprocess = {version="0.4.11", features=["unwind"]}
chrono = "0.4.19"
reqwest = { version = "0.11", features = ["blocking"] }
tokio = { version = "1", features = ["full"] }
signal-hook = "0.3.17"
nix = {version="0.28.0", features = ["signal"] }

[dev-dependencies]
py-spy-testdata = "0.1.0"
Expand Down
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ use console::style;

use config::{Config, FileFormat, RecordDuration};
use console_viewer::ConsoleViewer;
use libc::{SIGINT, SIGTERM};
use reqwest::StatusCode;
use signal_hook::iterator::Signals;
use nix::unistd::Pid;
use nix::sys::signal::{self, Signal};
use stack_trace::{Frame, StackTrace};

use chrono::{Local, SecondsFormat};
Expand Down Expand Up @@ -596,6 +600,15 @@ fn pyspy_main() -> Result<(), Error> {
let mut command = command
.spawn()
.map_err(|e| format_err!("Failed to create process '{}': {}", subprocess[0], e))?;

let mut signals = Signals::new(&[SIGINT, SIGTERM])?;
let child_pid = command.id();
std::thread::spawn(move || {
for sig in signals.forever() {
signal::kill(Pid::from_raw(child_pid.try_into().unwrap()), Signal::try_from(sig).unwrap()).unwrap();
println!("Received signal {:?}", sig);
}
});

#[cfg(target_os = "macos")]
{
Expand Down
4 changes: 2 additions & 2 deletions src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Sampler {
spy
}
Err(e) => {
initialized_tx.send(Err(e)).is_err();
let _ = initialized_tx.send(Err(e)).is_err();
return;
}
};
Expand Down Expand Up @@ -308,7 +308,7 @@ impl PythonSpyThread {
}
Err(e) => {
warn!("Failed to profile python from process {}: {}", pid, e);
initialized_tx.send(Err(e)).is_err();
let _ = initialized_tx.send(Err(e)).is_err();
return;
}
};
Expand Down

0 comments on commit bae454e

Please sign in to comment.