Forum Discussion
%run magic works manually but fails in pipeline when using runMultiple -cross kernel execution error
Hi everyone,
It was recently announced that %run magic is now supported for Python notebooks in Fabric, so I started using it to keep my common functions in a separate notebook.
My setup is as follows:
- I have a common notebook that contains shared functions.
- I have several processing notebooks that use those functions.
- I have an orchestrator notebook that runs everything using notebookutils.notebook.runMultiple().
In the orchestrator notebook, I first run the common notebook, and then execute the rest of the notebooks.
When I run the notebooks manually, everything works fine.
However, when the orchestrator notebook is executed from a pipeline, the cell that runs runMultiple() fails with the following error:
Notebook execution failed at Notebook service with http status code - '200',
please check the Run logs on Notebook, additional details -
Error name - Exception
Error value - NBS request failed: 400 - Cross kernel type execution is not supported in %run magic.
Child notebook kernel: python3.11, Current notebook kernel: .
It seems the pipeline execution is triggering a cross-kernel execution issue, but all notebooks are Python notebooks.
Has anyone run into this issue when using %run together with notebookutils.notebook.runMultiple() in a pipeline?
Any suggestions on how to resolve this would be greatly appreciated.
Thanks!
I've raised a support ticket with Microsoft, and they have confirmed this as a bug. They are working on a fix for a future release, though no ETA has been provided at this time.
17 Replies
- SteveCarlsberg2Regular Visitor
Same issue here! Running manually is fine, but running the notebook from a pipeline fails. I'm using python 3.11 version in all notebooks.
- mhosseiniFrequent Visitor
I've raised a support ticket with Microsoft, and they have confirmed this as a bug. They are working on a fix for a future release, though no ETA has been provided at this time.
- Murtaza_Ghafoor
Super User
mhosseini
Why this happening:The error happens because pipelines run notebooks in separate kernels, and %run does not support cross-kernel execution.
Temporary Solution:
Make sure every notebook that uses shared functions runs %run itself, instead of running it only in the orchestrator.
Example inside each notebook:
%run "./CommonFunctions"
But this still may not be ideal for pipelines.
Best Possible Approach:
Convert the Common Notebook to a Library
Fabric supports creating workspace libraries.
You can:
- Package your shared functions as a Python module
- Upload it as a workspace library
- Import it in notebooks
This is the most scalable enterprise approach.
Best Architecture for Fabric Notebooks
Instead of:
Common Notebook
↑
%run
↑
Processing Notebooks
↑
Orchestrator NotebookUse
Python Module / Library
↑
Processing Notebooks
↑
Orchestrator Notebook
↑
PipelineThis will remove the dependency on kernel.
If this helps, ✓ Mark as Kudos | Mark as Solution| Help Others
- mhosseiniFrequent Visitor
Thank you for your response. I should remphesis on the fact that I am using python notebooks, unlike spark environemtns which gives us a place to upload libraries, python does not provide such feature, would you let me know if there's a way to upload a custom library in python notebooks?
Also I tried several combinations:
1. Orchestrator runs common notebook & Processing runs common notebook > Cross runtime failure
2. Orchestrator does not run common notebook & Processing runs common notebook > Cross runtime failure
3. Orchestrator runs common notebook & Processingdoes not run common notebook > common functions are not available in processing notebook failure
- Murtaza_Ghafoor
Super User
mhosseini
Since you are using python notebooks so this option is not available but there is one workaround you may try this is to store your shared functions in a .py file inside Lakehouse Files or Workspace Files, and then import that file in your notebooks using sys.path.For example:
import sys
sys.path.append('/lakehouse/default/Files/utils')
import common_functionsWith this approach, the notebooks load the shared functions directly from the file system rather than relying on the same kernel session. Because of that, it works consistently for both manual notebook runs and pipeline executions.
If this helps, ✓ Mark as Kudos | Mark as Solution| Help Others
- deborshi_nag
Super User
Hello mhosseini
I have run an orchestrator notebook that runs other notebooks using notebookutils.notebook.runMultiple() where the first cell in each notebook is the %run command. I have run the orchestrator notebook in a pipeline, and it works fine.
The error message suggests a cross-kernel issue. Mixing Spark + Python notebooks in the same orchestration graph is not supported and commonly results in error.
In my workspace I have used Pyspark notebooks for both the orchestrator as well as the child notebooks - the environments used in each is the workspace default.
Here's the code I used for my test.
Orchestrator notebook:
from notebookutils import notebook # Define the DAG DAG = { "activities": [ { "name": "extract_customers", "path": "nb_extract_customers", # notebook item path/name "timeoutPerCellInSeconds": 120, "args": {"rows": 1000} }, { "name": "extract_products", "path": "nb_extract_products", "timeoutPerCellInSeconds": 120, "args": {"rows": 5000}, "dependencies": ["extract_customers"] }, { "name": "products_table", "path": "nb_build_product_table", "timeoutPerCellInSeconds": 300, "retry": 1, "retryIntervalInSeconds": 10, "dependencies": ["extract_products"] # wait for products first } ], "timeoutInSeconds": 1800, "concurrency": 3 } # Kick off the DAG; options can enable a DAG visualization and live progress result = notebook.runMultiple( DAG, {"displayDAGViaGraphviz": True} # optional visualization ) # 'result' is typically a structured object; you can inspect/log it print(result)Child notebook:
%run nb_common_functions# Parameters cell (mark as "Toggle parameter cell" in UI) rows = 1000 # default value, can be overridden by args # ... your logic here ... result = f"customers_ok_{rows}" hello("customers") from notebookutils import notebook notebook.exit(result)- mhosseiniFrequent Visitor
Hi deborshi_nag ,
Thank you for your response. I'm using python notebook. I already have spark notebooks and using the same method works. But Python notebooks have this issue.
- deborshi_nag
Super User
Thanks mhosseini, confirms my point - Mixing Spark + Python notebooks in the same orchestration graph is not supported, which is also what the error message indicates.
In practice:
- Controller / orchestrator - must be Spark
- Child notebooks - should also be Spark
- v-achippa
Community Support
Hi mhosseini,
Thank you for reaching out to Microsoft Fabric Community.
Thank you Murtaza_Ghafoor and deborshi_nag for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa
- v-achippa
Community Support
Hi @mhosseini,
We wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa