generated from PlexSheep/baserepo
uptime monitor python respects KeyboardInterrupt
This commit is contained in:
parent
0a6141af85
commit
6e7e2c9190
|
@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue