<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python UDF fails with UNAVAILABLE: Channel shutdownNow invoked in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61673#M31828</link>
    <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/79106"&gt;@daniel_sahal&lt;/a&gt;&amp;nbsp;thanks for your reply!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;There is no timeout set on the service side actually. The same MyOcr function, when invoked outside a UDF has no issues processing the records. It only fails when the function is wrapped inside a UDF. So, I am guessing it has something to do with the Python UDF Timeout or some other issue. We did change the configuration parameter `&lt;SPAN&gt;&lt;SPAN class=""&gt;spark.databricks.sql.execution.pythonUDFTimeout` to 200 seconds to allow the UDF to wait 200 seconds for each row before timing out. But that hasn't helped us either.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Maybe there's a different interpretation to the&amp;nbsp;spark.databricks.sql.execution.pythonUDFTimeout? Our understanding was that this refers to timeout at the row level, i.e, wait 200 seconds before a record goes to fail state. However, we could not find details on this anywhere in the databricks documentation except on one of the&amp;nbsp;&lt;A href="https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3245#M98" target="_blank" rel="noopener"&gt;other topics in this community&lt;/A&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Again, we are not sure if this is because of the timeout either. It could be something entirely different too.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Feb 2024 10:54:51 GMT</pubDate>
    <dc:creator>Bharathi7</dc:creator>
    <dc:date>2024-02-23T10:54:51Z</dc:date>
    <item>
      <title>Python UDF fails with UNAVAILABLE: Channel shutdownNow invoked</title>
      <link>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61650#M31823</link>
      <description>&lt;P&gt;I'm using a Python UDF to apply OCR to each row of a dataframe which contains the URL to a PDF document. This is how I define my UDF:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def extract_text(url: str):
    ocr = MyOcr(url)
    extracted_text = ocr.get_text()
    return json.dumps(extracted_text)

extract_text_udf = udf(lambda x: extract_text(x), StringType())

df2 = df2.withColumn('extracted_text', extract_text_udf(df2["url"]))
df2.display()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;For each row, it could take about 1 minute for the OCR to finish processing. But everytime I invoke the UDF, it keeps running for a long time and eventually terminates with this error message "&lt;SPAN&gt;SparkException: Job aborted due to stage failure: Task 2 in stage 253.0 failed 4 times, most recent failure: Lost task 2.3 in stage 253.0 (TID 375) (10.139.64.15 executor 0): com.databricks.spark.safespark.UDFException: UNAVAILABLE: Channel shutdownNow invoked"&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Why does this happen with this UDF alone? There are no issues executing other Python UDFs. And moreover, when I execute the same code outside a UDF, using a for loop for example, it works perfectly. I am not sure why the UDF keeps failing.&amp;nbsp;&lt;BR /&gt;Could someone help me with this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Databricks runtime version: 13.2&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 08:26:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61650#M31823</guid>
      <dc:creator>Bharathi7</dc:creator>
      <dc:date>2024-02-23T08:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python UDF fails with UNAVAILABLE: Channel shutdownNow invoked</title>
      <link>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61670#M31827</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/100647"&gt;@Bharathi7&lt;/a&gt;&amp;nbsp;It's really hard to determine what's going on without knowing what acutally MyOcr function does.&lt;/P&gt;&lt;P&gt;Maybe there's some kind of timeout on the service side? To many parallell connections?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 10:33:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61670#M31827</guid>
      <dc:creator>daniel_sahal</dc:creator>
      <dc:date>2024-02-23T10:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python UDF fails with UNAVAILABLE: Channel shutdownNow invoked</title>
      <link>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61673#M31828</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/79106"&gt;@daniel_sahal&lt;/a&gt;&amp;nbsp;thanks for your reply!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;There is no timeout set on the service side actually. The same MyOcr function, when invoked outside a UDF has no issues processing the records. It only fails when the function is wrapped inside a UDF. So, I am guessing it has something to do with the Python UDF Timeout or some other issue. We did change the configuration parameter `&lt;SPAN&gt;&lt;SPAN class=""&gt;spark.databricks.sql.execution.pythonUDFTimeout` to 200 seconds to allow the UDF to wait 200 seconds for each row before timing out. But that hasn't helped us either.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Maybe there's a different interpretation to the&amp;nbsp;spark.databricks.sql.execution.pythonUDFTimeout? Our understanding was that this refers to timeout at the row level, i.e, wait 200 seconds before a record goes to fail state. However, we could not find details on this anywhere in the databricks documentation except on one of the&amp;nbsp;&lt;A href="https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3245#M98" target="_blank" rel="noopener"&gt;other topics in this community&lt;/A&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Again, we are not sure if this is because of the timeout either. It could be something entirely different too.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 10:54:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/61673#M31828</guid>
      <dc:creator>Bharathi7</dc:creator>
      <dc:date>2024-02-23T10:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python UDF fails with UNAVAILABLE: Channel shutdownNow invoked</title>
      <link>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/62554#M31997</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/100647"&gt;@Bharathi7&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was that running MyOcr function outside UDF could run it sequentially, while as UDF in parallell - this might cause the service to timeout due to a big amount of requests coming in.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 08:40:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/python-udf-fails-with-unavailable-channel-shutdownnow-invoked/m-p/62554#M31997</guid>
      <dc:creator>daniel_sahal</dc:creator>
      <dc:date>2024-03-04T08:40:17Z</dc:date>
    </item>
  </channel>
</rss>

