WeichenXu123 commented on a change in pull request #24986: 
[SPARK-28185][PYTHON][SQL] Closes the generator when Python UDFs stop early
URL: https://github.com/apache/spark/pull/24986#discussion_r298493610
 
 

 ##########
 File path: python/pyspark/sql/tests/test_pandas_udf_scalar.py
 ##########
 @@ -850,6 +850,36 @@ def test_close(batch_iter):
             with self.assertRaisesRegexp(Exception, "reached finally block"):
                 self.spark.range(1).select(test_close(col("id"))).collect()
 
+    def test_scalar_iter_udf_close_early(self):
+        tmp_dir = tempfile.mkdtemp()
+
+        @pandas_udf('int', PandasUDFType.SCALAR_ITER)
+        def test_close(batch_iter):
+            generator_exit_caught = False
+            try:
+                for batch in batch_iter:
+                    yield batch
+                    time.sleep(0.5)
 
 Review comment:
   Sleep at last do not work. The sleep cmd cannot be interrupt (during sleep 
GeneratorExit cannot be raised)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to