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