<?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: How to %run a list of notebooks in Databricks in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21453#M14624</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thanks for the answer but it wasn't what I was after. It was about being able to provide a list as a variable.&lt;/P&gt;&lt;P&gt;I'll run the notebooks in series.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically can you %run {mynotebook}?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the answer is no.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/74518979/how-to-run-a-list-of-notebooks-in-databricks" alt="https://stackoverflow.com/questions/74518979/how-to-run-a-list-of-notebooks-in-databricks" target="_blank"&gt;https://stackoverflow.com/questions/74518979/how-to-run-a-list-of-notebooks-in-databricks&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2022 09:07:48 GMT</pubDate>
    <dc:creator>Philblakeman</dc:creator>
    <dc:date>2022-12-05T09:07:48Z</dc:date>
    <item>
      <title>How to %run a list of notebooks in Databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21450#M14621</link>
      <description>&lt;P&gt;I'd like to %run a list of notebooks from another Databricks notebook.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;my_notebooks = ["./setup", "./do_the_main_thing", "./check_results"]
for notebook in my_notebooks:
   %run notebook&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This doesn't work ofcourse. I don't want to use&amp;nbsp;dbutils.notebook.run() as this creates new jobs and doesn't return anything back - I want everything executable and queryable from the main notebook.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought perhaps it might be possible to import the actual module and run the function.&lt;/P&gt;&lt;P&gt;?%run shows the command points to IPython/core/magics/execution.py and&amp;nbsp;run is a method of the class&amp;nbsp;ExecutionMagics in the module&amp;nbsp;execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So perhaps, I could use&amp;nbsp;execution.ExecutionMagic.run() if I created an instance of the class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it's beyond me - tricky and I'm doubting it's an effective solution.&lt;/P&gt;&lt;P&gt;How can this be done?&lt;/P&gt;&lt;P&gt;Am I really stuck with:-&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%run ./a notebook
&amp;nbsp;
%run ./another_notebook
&amp;nbsp;
%run ./yet_another_hardcoded_notebook_name&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Eternally grateful for any help!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 13:01:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21450#M14621</guid>
      <dc:creator>Philblakeman</dc:creator>
      <dc:date>2022-11-21T13:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to %run a list of notebooks in Databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21451#M14622</link>
      <description>&lt;P&gt;Hi @Philip Blakeman​&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can do this using scala or python constructs using threads and futures. &lt;/P&gt;&lt;P&gt;You can download the notebook archive from this link. &lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;A href="https://docs.databricks.com/notebooks/notebook-workflows.html#run-multiple-notebooks-concurrently" target="test_blank"&gt;https://docs.databricks.com/notebooks/notebook-workflows.html#run-multiple-notebooks-concurrently&lt;/A&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;After that, based on your preference, set the number of parallel notebooks to be run using numNotebooksInParallel variable. If you just want 1 notebook at a time, you can do that too just by removing the unnecessary parts. &lt;/P&gt;&lt;P&gt;Be careful not to crash your driver by providing too many parallel notebooks.&lt;/P&gt;&lt;P&gt;Hope this helps.. Cheers.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2022 10:08:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21451#M14622</guid>
      <dc:creator>UmaMahesh1</dc:creator>
      <dc:date>2022-11-26T10:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to %run a list of notebooks in Databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21452#M14623</link>
      <description>&lt;P&gt;Hello @Philip Blakeman​&amp;nbsp;&lt;/P&gt;&lt;P&gt;Checking if your issue got resolved or if you are facing any issues with the above approach..&lt;/P&gt;&lt;P&gt;Cheers..&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2022 08:59:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21452#M14623</guid>
      <dc:creator>UmaMahesh1</dc:creator>
      <dc:date>2022-12-03T08:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to %run a list of notebooks in Databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21453#M14624</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thanks for the answer but it wasn't what I was after. It was about being able to provide a list as a variable.&lt;/P&gt;&lt;P&gt;I'll run the notebooks in series.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically can you %run {mynotebook}?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the answer is no.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/74518979/how-to-run-a-list-of-notebooks-in-databricks" alt="https://stackoverflow.com/questions/74518979/how-to-run-a-list-of-notebooks-in-databricks" target="_blank"&gt;https://stackoverflow.com/questions/74518979/how-to-run-a-list-of-notebooks-in-databricks&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 09:07:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21453#M14624</guid>
      <dc:creator>Philblakeman</dc:creator>
      <dc:date>2022-12-05T09:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to %run a list of notebooks in Databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21454#M14625</link>
      <description>&lt;P&gt;Please refer below code&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import scala.concurrent.{Future, Await}
import scala.concurrent.duration._
import scala.util.control.NonFatal
&amp;nbsp;
case class NotebookData(path: String, timeout: Int, parameters: Map[String, String] = Map.empty[String, String])
&amp;nbsp;
def parallelNotebooks(notebooks: Seq[NotebookData]): Future[Seq[String]] = {
  import scala.concurrent.{Future, blocking, Await}
  import java.util.concurrent.Executors
  import scala.concurrent.ExecutionContext
  import com.databricks.WorkflowException
&amp;nbsp;
  val numNotebooksInParallel = 4 
  // If you create too many notebooks in parallel the driver may crash when you submit all of the jobs at once. 
  // This code limits the number of parallel notebooks.
  implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(numNotebooksInParallel))
  val ctx = dbutils.notebook.getContext()
  
  Future.sequence(
    notebooks.map { notebook =&amp;gt; 
      Future {
        dbutils.notebook.setContext(ctx)
        if (notebook.parameters.nonEmpty)
          dbutils.notebook.run(notebook.path, notebook.timeout, notebook.parameters)
        else
          dbutils.notebook.run(notebook.path, notebook.timeout)
      }
      .recover {
        case NonFatal(e) =&amp;gt; s"ERROR: ${e.getMessage}"
      }
    }
  )
}
&amp;nbsp;
def parallelNotebook(notebook: NotebookData): Future[String] = {
  import scala.concurrent.{Future, blocking, Await}
  import java.util.concurrent.Executors
  import scala.concurrent.ExecutionContext.Implicits.global
  import com.databricks.WorkflowException
&amp;nbsp;
  val ctx = dbutils.notebook.getContext()
  // The simplest interface we can have but doesn't
  // have protection for submitting to many notebooks in parallel at once
  Future {
    dbutils.notebook.setContext(ctx)
    
    if (notebook.parameters.nonEmpty)
      dbutils.notebook.run(notebook.path, notebook.timeout, notebook.parameters)
    else
      dbutils.notebook.run(notebook.path, notebook.timeout)
    
  }
  .recover {
    case NonFatal(e) =&amp;gt; s"ERROR: ${e.getMessage}"
  }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 11:09:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-run-a-list-of-notebooks-in-databricks/m-p/21454#M14625</guid>
      <dc:creator>Ajay-Pandey</dc:creator>
      <dc:date>2022-12-07T11:09:34Z</dc:date>
    </item>
  </channel>
</rss>

