This is an automated email from the ASF dual-hosted git repository.

stigahuang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 0292e296c0ebcb191fb988f2582856023dd1bb70
Author: Riza Suminto <[email protected]>
AuthorDate: Thu Sep 11 11:25:09 2025 -0700

    IMPALA-14426: Deflake TestImpalaShell.test_cancellation
    
    TestImpalaShell.test_cancellation start failing when run with Python 3.9
    with following error message
    
    RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'>
    
    This patch is a quick fix the by changing the stderr write from using
    print() to os.write(). Note that the thread-safetyness isssue within
    _signal_handler in impala_shell.py during query cancellation still
    remains.
    
    Testing:
    Run and pass test_cancellation in RHEL9 with Python 3.9.
    
    Change-Id: I5403c7b8126b1a35ea841496fdfb6eb93e83376e
    Reviewed-on: http://gerrit.cloudera.org:8080/23416
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 shell/impala_shell/impala_shell.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/shell/impala_shell/impala_shell.py 
b/shell/impala_shell/impala_shell.py
index 14b329e3d..a952fa7f8 100755
--- a/shell/impala_shell/impala_shell.py
+++ b/shell/impala_shell/impala_shell.py
@@ -736,7 +736,7 @@ class ImpalaShell(cmd.Cmd, object):
     for cancel_try in xrange(ImpalaShell.CANCELLATION_TRIES):
       try:
         self.imp_client.is_query_cancelled = True
-        print(ImpalaShell.CANCELLATION_MESSAGE, file=sys.stderr)
+        os.write(sys.stderr.fileno(), 
ImpalaShell.CANCELLATION_MESSAGE.encode('utf-8'))
         new_imp_client = self._new_impala_client()
         new_imp_client.connect()
         try:
@@ -752,9 +752,9 @@ class ImpalaShell(cmd.Cmd, object):
         if err_msg in ['ERROR: Cancelled', 'ERROR: Invalid or unknown query 
handle'] or \
           ('\nCancelled' in err_msg or '\nInvalid or unknown query handle' in 
err_msg):
           break
-        err_details = "Failed to reconnect and close (try %i/%i): %s"
-        print(err_details % (cancel_try + 1, ImpalaShell.CANCELLATION_TRIES, 
err_msg),
-              file=sys.stderr)
+        err_details = "Failed to reconnect and close (try {}/{}): {}".format(
+            cancel_try + 1, ImpalaShell.CANCELLATION_TRIES, err_msg)
+        os.write(sys.stderr.fileno(), err_details.encode('utf-8'))
 
   def _is_quit_command(self, command):
     # Do a case insensitive check

Reply via email to