# Executing 2 notebooks against the same kernel

**URL:** <https://discourse.jupyter.org/t/executing-2-notebooks-against-the-same-kernel/6024>\
**Category:** nbconvert\
**Tags:** help-wanted\
**Created:** [September 18, 2020, 2:16am UTC](https://discourse.jupyter.org/t/executing-2-notebooks-against-the-same-kernel/6024 "2020-09-18T02:16:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jess.garcia](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jess.garcia](https://discourse.jupyter.org/u/jess.garcia)\
**Post date:** [September 18, 2020, 2:16am UTC](https://discourse.jupyter.org/t/executing-2-notebooks-against-the-same-kernel/6024/1 "2020-09-18T02:16:48Z")

</div>

Hi all,

I’m trying to execute 2 notebooks against same kernel from jupyter(lab).

nb1 defines a variable (a=1) and nb2 prints it (print(a)). nb1 executes successfully and, while nb2 executes, it does not seem to attach to the newly started kernel, for I get “variable ‘a’ not found”. No other errors or problems.

I assume that, if both nbs were running on the same kernel, nb2 should be able to print a (just as when you attach 2 notebooks to the same kernel via the GUI).

I’ve tried several variations to no avail.

I’m using nbconvert 5.6.1 / jupyter\_client 6.1.6.

I used the _executenb_ notation “kernel=(km,kc)” that I found online, but I’m not sure that’s the right way to pass the kernel manager/client to executenb (at least I don’t get any errors).

Any ideas of what might be wrong?

Thanks!

JESS

```auto
from nbconvert.preprocessors.execute import executenb
from nbformat import read as nbread
from jupyter_client.manager import start_new_kernel

nb1 = nbread('nb1.ipynb', as_version=4) <--- defines "a"
nb2 = nbread('nb2.ipynb', as_version=4) <--- prints "a"
kernel_name = nb.metadata.get('kernelspec', {}).get('name', 'python')
km, kc = start_new_kernel(kernel_name=kernel_name)

executenb(nb1, kernel=(km, kc))
executenb(nb2, kernel=(km, kc))

```
