godeomt opened a new pull request, #54636: URL: https://github.com/apache/spark/pull/54636
### What changes were proposed in this pull request? This PR fixes a deadlock issue during Python 3.12+ shutdown in `test_connect_session`. It safely skips `self._channel.close()` inside `client.close()` and `__del__()` if the Python interpreter is shutting down (`sys.is_finalizing()`). ### Why are the changes needed? To prevent flaky CI timeouts (e.g., hanging for 450s). The deadlock occurs when `self._channel.close()` is called during `__del__`. gRPC attempts to spawn a new background thread to clean up ongoing RPCs, but Python 3.12+ strictly blocks new thread creation during interpreter shutdown, causing an infinite hang. By checking `sys.is_finalizing()`, we can safely skip the gRPC channel closure. The OS will reclaim the network sockets and memory resources upon process exit anyway. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? - Tested locally by running `python/run-tests.py --testnames pyspark.sql.tests.connect.test_connect_session` multiple times without any hangs. - Relying on GitHub Actions CI to verify the flaky test stability. ### Was this patch authored or co-authored using generative AI tooling? No. -- 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]
