uptime monitor python respects KeyboardInterrupt

This commit is contained in:
Christoph J. Scherr 2023-07-09 20:12:34 +02:00
parent 0a6141af85
commit 6e7e2c9190
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
1 changed files with 5 additions and 6 deletions

View File

@ -30,8 +30,6 @@ use std::time::SystemTime;
use pyo3::prelude::*; use pyo3::prelude::*;
use signal_hook::consts::SIGINT;
use crate::divider; use crate::divider;
//// TYPES ///////////////////////////////////////////////////////////////////////////////////////// //// TYPES /////////////////////////////////////////////////////////////////////////////////////////
@ -289,17 +287,18 @@ pub fn continuous_uptime_monitor(success_ratio_target: u8, urls: Vec<String>, in
/// `KeyboardInterrupt` exception. /// `KeyboardInterrupt` exception.
#[pyfunction] #[pyfunction]
#[pyo3(name = "continuous_uptime_monitor")] #[pyo3(name = "continuous_uptime_monitor")]
pub unsafe fn py_continuous_uptime_monitor( pub fn py_continuous_uptime_monitor(
py: Python,
success_ratio_target: u8, success_ratio_target: u8,
urls: Vec<String>, urls: Vec<String>,
interval: u64, interval: u64,
) { ) -> PyResult<()>{
// execute the function in a different thread // execute the function in a different thread
let _th = std::thread::spawn(move || { let _th = std::thread::spawn(move || {
continuous_uptime_monitor(success_ratio_target, urls, interval); continuous_uptime_monitor(success_ratio_target, urls, interval);
}); });
// while we dont receive a SIGINT, just go on and check every once in a while loop {
while pyo3::ffi::PyErr_CheckSignals() != SIGINT { Python::check_signals(py)?;
std::thread::sleep(std::time::Duration::from_millis(100)) std::thread::sleep(std::time::Duration::from_millis(100))
} }
} }