File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -279,4 +279,21 @@ pub(crate) mod _signal {
279
279
Err ( vm. new_value_error ( "signal number out of range" . to_owned ( ) ) )
280
280
}
281
281
}
282
+
283
+ /// Similar to `PyErr_SetInterruptEx` in CPython
284
+ ///
285
+ /// Missing signal handler for the given signal number is silently ignored.
286
+ pub fn set_interrupt_ex ( signum : i32 , vm : & VirtualMachine ) -> PyResult < ( ) > {
287
+ assert_in_range ( signum, vm) ?;
288
+
289
+ match signum as usize {
290
+ SIG_DFL | SIG_IGN => Ok ( ( ) ) ,
291
+ _ => {
292
+ // interrupt the main thread with given signal number
293
+ //? Should follow with https://github.com/python/cpython/blob/b2afe482f21b826d53886a69ea2c99d0d940c59a/Modules/signalmodule.c#L301-L381
294
+ //? or another way we can do in Rust?
295
+ Ok ( ( ) )
296
+ }
297
+ }
298
+ }
282
299
}
Original file line number Diff line number Diff line change @@ -304,6 +304,11 @@ pub(crate) mod _thread {
304
304
vm. state . thread_count . fetch_sub ( 1 ) ;
305
305
}
306
306
307
+ #[ pyfunction]
308
+ fn interrupt_main ( signum : OptionalArg < i32 > , vm : & VirtualMachine ) -> PyResult < ( ) > {
309
+ crate :: stdlib:: signal:: _signal:: set_interrupt_ex ( signum. unwrap_or ( libc:: SIGINT ) , vm)
310
+ }
311
+
307
312
#[ pyfunction]
308
313
fn exit ( vm : & VirtualMachine ) -> PyResult {
309
314
Err ( vm. new_exception_empty ( vm. ctx . exceptions . system_exit . to_owned ( ) ) )
You can’t perform that action at this time.
0 commit comments