timsaucer commented on code in PR #1311:
URL: 
https://github.com/apache/datafusion-python/pull/1311#discussion_r2574411647


##########
src/utils.rs:
##########
@@ -77,14 +78,24 @@ where
     let runtime: &Runtime = &get_tokio_runtime().0;
     const INTERVAL_CHECK_SIGNALS: Duration = Duration::from_millis(1_000);
 
-    py.allow_threads(|| {
+    py.detach(|| {
         runtime.block_on(async {
             tokio::pin!(fut);
             loop {
                 tokio::select! {
                     res = &mut fut => break Ok(res),
                     _ = sleep(INTERVAL_CHECK_SIGNALS) => {
-                        Python::with_gil(|py| py.check_signals())?;
+                        Python::attach(|py| {
+                                // Execute a no-op Python statement to trigger 
signal processing.
+                                // This is necessary because 
py.check_signals() alone doesn't
+                                // actually check for signals - it only raises 
an exception if
+                                // a signal was already set during a previous 
Python API call.
+                                // Running even trivial Python code forces the 
interpreter to
+                                // process any pending signals (like 
KeyboardInterrupt).
+                                let code = CString::new("pass").unwrap();
+                                py.run(code.as_c_str(), None, None)?;

Review Comment:
   minor:
   
   ```suggestion
                                   py.run(cr"pass", None, None)?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to