fix(processing_engine): ensure default SIGINT behavior from python. (#25957)

fix/enable-workspace-lints-on-all-crates
Jackson Newhouse 2025-02-03 14:31:04 -08:00 committed by GitHub
parent 0fffcc8c37
commit f58f3439cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -1,4 +1,6 @@
use observability_deps::tracing::debug; use observability_deps::tracing::debug;
use pyo3::Python;
use std::ffi::CString;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use std::sync::Once; use std::sync::Once;
@ -46,8 +48,21 @@ fn set_pythonpath(venv_dir: &Path) -> Result<(), std::io::Error> {
pub fn init_pyo3() { pub fn init_pyo3() {
PYTHON_INIT.call_once(|| { PYTHON_INIT.call_once(|| {
pyo3::prepare_freethreaded_python(); pyo3::prepare_freethreaded_python();
})
// This sets the signal handler fo SIGINT to be the default, allowing CTRL+C to work.
// See https://github.com/PyO3/pyo3/issues/3218.
Python::with_gil(|py| {
py.run(
&CString::new("import signal;signal.signal(signal.SIGINT, signal.SIG_DFL)")
.unwrap(),
None,
None,
)
.expect("should be able to set signal handler.");
});
});
} }
#[cfg(unix)] #[cfg(unix)]
pub(crate) fn initialize_venv(venv_path: &Path) -> Result<(), VenvError> { pub(crate) fn initialize_venv(venv_path: &Path) -> Result<(), VenvError> {
use std::process::Command; use std::process::Command;