<?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 'NotebookHandler' object has no attribute 'setContext' in pyspark streaming in AWS in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/42798#M845</link>
    <description>&lt;P&gt;I am facing issue while calling dbutils.notebook.run() inside of pyspark streaming with concurrent.executor. At first the error is "pyspark.sql.utils.IllegalArgumentException: Context not valid. If you are calling this outside the main thread,&lt;BR /&gt;you must set the Notebook context via dbutils.notebook.setContext(ctx), where ctx is a value retrieved from the main thread (and the same cell)&lt;BR /&gt;via dbutils.notebook.getContext()."&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But, I didn't see setContext and getContext in python code&lt;/P&gt;</description>
    <pubDate>Tue, 29 Aug 2023 14:18:07 GMT</pubDate>
    <dc:creator>Sreekanth_N</dc:creator>
    <dc:date>2023-08-29T14:18:07Z</dc:date>
    <item>
      <title>'NotebookHandler' object has no attribute 'setContext' in pyspark streaming in AWS</title>
      <link>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/42798#M845</link>
      <description>&lt;P&gt;I am facing issue while calling dbutils.notebook.run() inside of pyspark streaming with concurrent.executor. At first the error is "pyspark.sql.utils.IllegalArgumentException: Context not valid. If you are calling this outside the main thread,&lt;BR /&gt;you must set the Notebook context via dbutils.notebook.setContext(ctx), where ctx is a value retrieved from the main thread (and the same cell)&lt;BR /&gt;via dbutils.notebook.getContext()."&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But, I didn't see setContext and getContext in python code&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:18:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/42798#M845</guid>
      <dc:creator>Sreekanth_N</dc:creator>
      <dc:date>2023-08-29T14:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: 'NotebookHandler' object has no attribute 'setContext' in pyspark streaming in AWS</title>
      <link>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/44450#M1035</link>
      <description>&lt;P&gt;The error message you're encountering in PySpark when using dbutils.notebook.run() suggests that the context in which you are attempting to call the run() method is not valid. PySpark notebooks in Databricks have certain requirements when it comes to using dbutils.notebook.run() in a multi-threaded environment.&lt;/P&gt;&lt;P&gt;Here are some steps you can follow to address this issue:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Set Notebook Context:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;As indicated in the error message, you should set the notebook context using dbutils.notebook.setContext(ctx) before calling dbutils.notebook.run(). The ctx value should be retrieved from the main thread in the same cell.&lt;/LI&gt;&lt;/UL&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;# Retrieve the context in the main thread&lt;BR /&gt;ctx = dbutils.notebook.entry_point.getDbutils().notebook().getContext()&lt;/P&gt;&lt;P&gt;# Set the context&lt;BR /&gt;dbutils.notebook.setContext(ctx)&lt;/P&gt;&lt;P&gt;# Now you can call dbutils.notebook.run()&lt;BR /&gt;dbutils.notebook.run(...)&amp;nbsp;&lt;A href="https://qrcodescanner.org/" target="_self"&gt;&lt;FONT color="#FFFFFF"&gt;QR Code Scanner&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;The key is to set the notebook context correctly and ensure that any concurrent execution is managed in a way that does not interfere with the notebook's context and execution.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 Sep 2023 05:39:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/44450#M1035</guid>
      <dc:creator>Kevin3</dc:creator>
      <dc:date>2023-09-12T05:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: 'NotebookHandler' object has no attribute 'setContext' in pyspark streaming in AWS</title>
      <link>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/54769#M1930</link>
      <description>&lt;P&gt;Hello Kevin3,&lt;/P&gt;&lt;P&gt;In pyspark, the below line gets the context:&lt;BR /&gt;&lt;STRONG&gt;ctx = dbutils.notebook.entry_point.getDbutils().notebook().getContext()&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But, this "&lt;SPAN&gt;dbutils.notebook.setContext(ctx)&lt;/SPAN&gt;" doesn't set the Context()&lt;/P&gt;&lt;P&gt;I was searching the directory and found the method somewhat like this.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;dbutils.notebook.entry_point.getDbutils().notebook().setContext(ctx)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;but even after using this I am unable to start the child notebook from the parent notebook. It gives the below error:&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;EM&gt;"Exception due to : Context not valid. If you are calling this outside the main thread, you must set the Notebook context via dbutils.notebook.setContext(ctx), where ctx is a value retrieved from the main thread (and the same cell) via dbutils.notebook.getContext()."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Maybe I am not using it the correct way. Let me know if you have a workaround for this situation:&lt;/P&gt;&lt;P&gt;1. Attaching the functions that I am using to run the child notebook.&lt;/P&gt;&lt;P&gt;2. I am running the function "execute_child_nb" in the stream microbatch.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-12-06 at 5.34.02 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/5503i2D83F75E167415C6/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-12-06 at 5.34.02 PM.png" alt="Screenshot 2023-12-06 at 5.34.02 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Abhijit&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2023 12:07:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/notebookhandler-object-has-no-attribute-setcontext-in-pyspark/m-p/54769#M1930</guid>
      <dc:creator>Arai</dc:creator>
      <dc:date>2023-12-06T12:07:09Z</dc:date>
    </item>
  </channel>
</rss>

